Keep Getting Wrong Variable Values?

Oct 24, 2014

Whenever I run this I get:

There are not enough funds to do that

Balance: $0.0
Monthly Interest Rate: 0.375%
Account Start Date: Fri Oct 24 08:03:40 EDT 2014

I assumed that this is because the constructor Account(); is setting the variables to 0 every time the program runs even though I'm passing other variables through to methods and constructors. I've looked up similar programs and this is how it's done though. The steps to my homework say to create a no-arg constructor Account() that creates a default(0) account Id and balance. What did I do wrong?

import java.util.Date;
public class Account {
 private int Id;
private double balance;
private double annualInterestRate;
private Date dateCreated = new Date();
 public static void main (String [] args){
//Objects of Account to get non-static methods

[code]....

View Replies


ADVERTISEMENT

JSF :: Dialog Inside Datatable With Button Displays Wrong Variable Value

Nov 27, 2014

I have a bookings table where customers can view their bookings and in the table there is a button with a command button that onclick goes to the dialogue to display the variable petUpdate value but if you have 2 bookings then all the update buttons display the value of the last petUpdate in the arrayList.

DataTable with the button

<p:dataTable
id="bookingTable"
var="customerBooking"
value="#{booking.sessionBookingList}"
editable="true"
style="margin:0px 0px 20px 100px;font-size:15px;width:600px;"
>

Code in the above datatable.......The commented out output label displays the correct value for each but when the button is clicked the dialog only displays the last ones value

<p:column headerText="Check Updates" style ="width:50px;">
<!-- <h:outputLabel value="#{customerBooking.petUpdate}"></h:outputLabel> -->
<p:dialog header="#{customerBooking.petName}'s Status" widgetVar="dlg1" minHeight="60" minWidth="60" maxWidth="60">
<h:outputText value="#{customerBooking.getPetUpdate()}" />
</p:dialog>
<p:commandButton value="?" onclick="PF('dlg1').show();" style ="width:40px;">
</p:commandButton>
</p:column>

View Replies View Related

Getting Wrong Values When Calculating Perimeter And Area?

Mar 22, 2015

I've been given a school assignment that reads, "Rewrite the main class Geometry so it takes in the dimensions for the triangle and ellipse as user inputs and create a Triangle and an Ellipse class. Use the appropriate variable types, constants, variable names and computational formulas.

Triangle class will have a computePerimeter and a computeArea methods Ellipse class will have a computeArea method Create Report class

• Create a method createReport that takes the values returned from Triangle and Ellipse and combines them in the following message and displays it. Format the values so that they have 2 decimals.

“The triangle has a perimeter of [perimeter] with an area of [area] while the ellipse has an area of [area]”

• Create a method switchReport that takes the original string from createReport and changes the message to display using the available methods in the String class

“The ellipse has an area of [area] while the triangle has an area of [area] with a perimeter of [perimeter]”"

I've run into a problem when creating the createReport method. Everytime i run it i get incorrect values for the perimeter and area (namely i get zero every time).

my code is as follows:

public class Triangle
{
public double base;
public double height;
public double hypotenuse;
private double tArea;
private double perimeter;
  public Triangle()
{
base = 0;
height = 0;
hypotenuse = 0;

[code]....

For the triangle class and

public class Report {
  Triangle tri2 = new Triangle();
Ellipse eli2 = new Ellipse();
  public Report() { 

public void createReport() {
System.out.println("The triangle has a perimeter of "+tri2.computePerimeter() +" with an area of " +tri2.computeTArea() +" while the ellipse has an area of " +eli2.computeEArea() );
}

for the report class.the Geometry class allows you to input values and if i skip the report and simply print the perimeter and area they are correct. However with the report class it simply gives me zeros.

View Replies View Related

JSF :: ValueChangeEvent NewValue Method Giving Wrong Value When Component Values Change Indirectly

Aug 1, 2014

My form looks like this:

<h:form>
<h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">
<p:outputLabel for="filetype" value="FileType: " />
<p:selectOneRadio valueChangeListener="#{selectView.changeServerAndSignmethod}" onchange="submit()" id="filetype" value="#{selectView.filetype}">
<f:selectItems value="#{selectView.filetypes}" itemLabel="#{filetype}" itemValue="#{filetype}" />
</p:selectOneRadio>
<p:outputLabel for="signmethod" value="Sign Method: " />
<p:selectOneMenu valueChangeListener="#{selectView.changeServers}" onchange="submit()" id="signmethod" value="#{selectView.signmethod}">
<f:selectItems value="#{selectView.signmethods}" itemLabel="#{signmethod}" itemValue="#{signmethod}" />

[code]....

As you can see there are two listener in my xhtml file one for filetype and other for signmethod. When filtype changes signmethod has to change which in turn changes servers. And if user changes signmethod using dropdown then also server should change. But my problem is when filetype changes, both the listeners are called, as signmethod also changea but the value in event object (e.getNewValue()) is not the new one but old one. Here is the SelectView Bean.This is the static initialisation part just for checking the output at the end of question.

static {
initFiletypes.add("Windows");
initFiletypes.add("Mobile");
initFiletypes.add("Mac");
initFiletypes.add("Solaris");
initFiletypes.add("Jar");

windowsSignmethods.add("Microsoft");
windowsSignmethods.add("Driver");
windowsSignmethods.add("Driver_Pagehash");
windowsSignmethods.add("HDR");
windowsSignmethods.add("Java2");
windowsSignmethods.add("Javame");
windowsSignmethods.add("MicrosftApps");

[code]....

I am changing servers in changeServerAndSignmethod by selecting first signmethod from signmethod arraylist which is giving correct result. But changeServers is also getting fired taking wrong event object's newValue method and changing servers to wrong values. When changeServers is fired bydirectly changing signmethod, by dropdown, it gives correct result. Is there a way I can stop changeServers to fire when the change came from changing filetypes rather than direct change by user on signmethod selectOneMenu.

View Replies View Related

Can Assign Multiple Values To One Variable

Apr 25, 2014

Can I assign multiple values to one variable? For example I want myNum = 0 thru 9 you see im trying to program a password checker program to verify that the password meets all the criteria 8 char long, 1 upper case, 1 lower case, 1 numeric, 1 special, and don't contain and or end

View Replies View Related

One Object / One Instance Variable - Different Values?

Feb 5, 2015

Let's pretend I'm working on an RPG. Like in all RPGs, there are items found all throughout the imaginary world. Each player and NPC can obtain an item. My question will concern those items.

In other words, I'd like to use instances of a class in multiple places of the code. Each instance will have its own, individual values of instance variables, with one obvious exception: itemQuantity should have a different value in playerInventory, npcInventory, etc. Also, I'd like a list of all items that can be found in the game. This list doesn't need itemQuantity at all.

class Items {
String itemName;
float itemWeight;
int itemQuantity;

[Code] ....

The question is: should I really make itemQuantity an instance variable of the Item class? It seems as though for each copy of the Item class I should create a separate copy with different value of itemQuantity, but that's not very efficient. Where is the error in my logic?

What's important is that there may be plenty items in a game and a player may be given power to create new items during the course of the game.

View Replies View Related

New Instance Variable Values Not Updating

May 6, 2015

Alright, I have a JavaFX gui that is creating a new instance of data calculation to graph in a chart; however, the data is not updating each time the Platform.runLater() feature executes. Each time an event occurs, a new instance with the same variable name occurs. I use to get methods to retrieve the data I want, so shouldn't the values update each time the new instance is created? This is a very condensed version of what happens with the event, but this is what is not working correctly.

Event:
solarPlot = new SolarTracker();
solarPlot.getElevation();
solarPlot.getAzimuth();
Class constructor :
public SolarTracker() {

[Code] .....

View Replies View Related

Constructors - How To Put 3 Values Of Each Variable Without Replacing Last Inputted One

Oct 2, 2014

Java Code:

public class Puppy{
int puppyAge;
public Puppy(String name){
// This constructor has one parameter, name.
System.out.println("Passed Name is :" + name );
}
public void setAge( int age ){
puppyAge = age;

[Code] ....

How do I put 3 values of the each variable without replacing the last inputted one?

Like when I input "Tommy" and input another name "Gerald", "Tommy" won't be replaced by "Gerald" when I input again.

View Replies View Related

BinarySearch Gone Wrong

Jan 25, 2015

Searching methods and sorting methods, I tried some (SelectionSort, InsertionSort, BubbleSort, SequentialSearch) and they all work, but I am having problems right now with my BinarySearch method. The problem(s) I have right now is that the method is only finding some numbers in my array, such as 1 and 8, but when I search for the other ones it only buffers and the program has to be stopped manually, since it doesn't print anything. I tried rearranging the while-loop's circumstances but that didn't work.

how to optimize my coding for future tasks so I dont get the same problem(s).

public class BinarySearch {
public static void main(String[] args) {
int[]A = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int searchedNumber = 3;

[code]....

View Replies View Related

JRE Uses Wrong Timezone

Jun 26, 2015

I have a problem with timezone in my java application. My current/correct timezone is "Europe/Berlin" or CEST. When I type the following command as my user I get the correct output back:
 
$ date "+%Z %z"
CEST +0200
 
But when I run my java application it is using the timezone GMT+0100. I have executed the following Java code to verify:
 
import java.util.Date;
import java.util.TimeZone;
public class TimeTest {
    public static void main(String args[]) {
        long time = System.currentTimeMillis();

[Code] ....
 
When I run it the following output is generated:

Current time in milliseconds = 1435319087443 => Fri Jun 26 12:44:47 GMT+01:00 2015
Current time zone: GMT+01:00
Fri Jun 26 12:44:47 GMT+01:00 2015
 
So where does java get its timezone from? It's different from the default system timezone.
 
I am running on Redhat 6.6 with Java 1.7.0_79
 
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

View Replies View Related

Apache POI Method Returning Wrong Value

May 20, 2014

I'm using apache POI to input data from a excel database. I have a method that is supposed to count the number of rows containing data so I can use that number to initialize an object array. It's returning one more than the actual number of rows and I can't figure out why.

public int getDataRange() throws IOException{
int rowCount = 0;
Iterator<Row> rows = sheet.rowIterator();
while(rows.hasNext()){
HSSFRow row = (HSSFRow) rows.next();
rowCount++;

[Code] .....

I get an array index out of bounds exception at the highlighted line.

View Replies View Related

Wrong Version Appearing For Java Command

Sep 8, 2011

I am a novice to coding and very new to Java. It appears that I am having a similar problem as the user above "Scott Allen". With a few exceptions. My issue is that when I run the command "javac" from the command prompt I am receiving the same error:- "javac is not recognized as an internal or external command, operable program or batch file"

After reading the comments from above I have configured my System Variables "Path" and "JAVA_HOME" to match the following:
JAVA_HOME: C:Program FilesJavajdk1.6.0_21in
Path: %JAVA_HOME%in; [First Variable]

There is no "Path" User variable on my computer, although there is a "TEMP" and "TMP" in the User Environment variables.

Currently I have the following Java related software installed:
- C:Program FilesJavajre6
- C:Program FilesJavajdk1.6.0_21
- C:Program FilesSunJavaDB
- C:Program FilesEclipse-jee-galileo-3.5.2

I have confirmed the "javac.exe" is located within the in directory of Javajdk.1.6.0_21..When I send "Java -version" to the command prompt the following is returned: java version "1.6.0_26"..Immediately I noticed that the version is wrong, but don't know why or what to do. Below is the output from the command "Java" using the command prompt.

Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)

where options include:

-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.

[code]....

View Replies View Related

Adding Message That A Wrong Character Has Been Entered?

Nov 6, 2014

So the idea of this program is that you enter a number, it will give out a radius ... After the radius is given then, it will ask if you want to continue yes or no, if yes then it will repeat the process. If you select no then you will be greeted with a message saying "programme complete, See you later" ...

This all works fine and the code is below... however I want to add a pop up message if someone enters an invalid Character (anything that is not a number) ...

View Replies View Related

Get Wrong Type Error When Calling Methods

Apr 21, 2015

Basically I'm trying to code this program but I keep getting error can't be applied to given types. I know it has to do with my method trying to be called by an array, but I'm just kinda lost.

Write a program that prompts the user to input cash amounts and use a method to calculate the average amount for a week given 7 inputs of daily cash intake amounts for a cash register. Use an array to store the values. Recall that average is the sum of the values divided by the number of values. The method should take argument(s) of type double and return average weekly cash amount as a double.

Make sure you test your program using the test data given below and calls the averageCash() method defined above passing in the values. Verify that the input values are greater than or equal to 0. Negative numbers are not allowed. Output the values used and the averageCash value.

import java.util.*;
public class ArrayHandout {
public static void main(String args[]) {
int[] a=new int[6];
Scanner sc=new Scanner(System.in);

[Code] ....

View Replies View Related

Wrong Entries Deleting In Array List

Aug 15, 2014

I have a problem with this application , I have a button that allows users to delete entry's from the array list, but i've noticed when i go back and click display entry's the correct entry has not been deleted.....for example if i enter a,1,2 then b,1,2, then c,1,2 in fields, then delete c,1,2 when i actually go to display the data entered a,1,2 will be gone not the one i entered.

So it seems to be deleting the entry at index 0 of the array list no matter what and not the chosen item..Delete Button Code

private void deleteBtnActionPerformed(java.awt.event.ActionEvent evt)
{
if (numTf.getText().equals("") || nameTf.getText().equals("") || yearTf.getText().equals(""))
{
JOptionPane.showMessageDialog(null, "All fields must be full");
}
else if (count == 0)

[code]....

View Replies View Related

JavaFX 2.0 :: BarChart Wrong Data Displayed

Aug 28, 2014

I'm using BarChart and I've a very strange problem. Is not very simple create a test case to understand where is the problem.

In the first image is displayed a bar with the value of 2 but as you can see the y axis is not correct.

In the second image the value displayed is 4 but the y axis is completely busted.

Important thing: In my real app I change data of the chart every time the user change a combobox value (the period).
 
First image
Second image
 
This is a test case that simulate what I'm doing in my app with the only difference that data are fetched remotely with an async request in my real app.
 
Chart.java

public class Chart extends Application implements Initializable {
    @FXML
    private BarChart<String, Integer> chart;
    private ObjectProperty<ObservableList<Series<String, Integer>>> seriesProperty = new SimpleObjectProperty<ObservableList<Series<String, Integer>>>();

[Code] .....

Unfortunately with this simple test case the chart display correctly data.

View Replies View Related

JDBC :: Oracle UCP Connecting To Wrong Port

Apr 10, 2015

I am trying to connect to Sql Server database using Oracle UCP with sqljdbc4-3.0 JDBC driver for Sql Server,with different ports and instances.

– the issue is with the port being ignored in the server string.

For example, using port 1440 connects to the default instance (which is on port 1433) rather than MSSQLINSTANCE1 which is on 1440.

Below are Server hosts used.

sql005.sqlasoftware.com (connects correctly to the default instance)
sql005.sqlasoftware.com:1440 (connects incorrectly to the default instance on port 1433)
sql005.sqlasoftware.comMSSQLINSTANCE1 (connects correctly to the named instance)

View Replies View Related

Web Services :: Constructor Parameters Wrong Order In Wsdl2java

Feb 5, 2015

I have generated wsdl2java code using axis 1.4 . One classes has 2 constructor methods (one default constructor and other one has 2 parameters). Other classes that inherit from one class have the constructor parameters in the wrong order. The schema files is correct as they come from the OTA specification. What should be done to get rid of this ordering problem in constructor

View Replies View Related

Polymorphism / Dynamic Binding - Invoking Wrong Method

Jan 9, 2014

Why is the equals-method in the super-class invoked? Shouldn't the equals-method in the sub-class be invoked(at least in the first if-statement since b2 is a B(i know B is also an A))?Is the equals-method overridden? Or does B have its own equals-method?

class SomeClass{
public static void main(String[] args) {

B b1 = new B(123,1);
B b2 = new B(123,2);

[code]...

View Replies View Related

Java Fraction Calculation Compiles But Output Is Wrong

May 9, 2014

So all the errors in the code is fixed but its now got the wrong output

what I get:

Enter numerator; then denominator.
5
8
5/8
Enter numerator; then denominator.
4
10
4/10
Sum:0/0

it should be:

Enter numerator; then denominator.
5
8
5/8
Enter numerator; then denominator.
4
10
4/10
Sum: 82/80 1.025
Product: 20/80 0.25
Enter numerator; then denominator.
6 0
infinity

here is the code

Fraction.java
public class Fraction { //declares that it's a class that can be intantiated
private int numer; // private intager for numerator
private int denom; // private intager for denominator

[Code] ....

View Replies View Related

Java-8 :: Button Width Calculated Wrong Under Windows?

May 7, 2014

I am developing a JavaFX application under Java 8 on my Ubuntu 14.04 (32 bit) system. When I run it on the Ubuntu box, all is fine, but when I run it under Windows 7 Home Premium (64 bit) with the same Java8 release installed, all my buttons have their text ellipsised (sp?). Why the behavior is different? Or is this a bug in JavaFX? Here are the particulars:
 
fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?><?import java.util.*?><?import javafx.geometry.*?><?import javafx.scene.*?><?import javafx.scene.control.*?><?import javafx.scene.layout.*?><?import javafx.scene.text.*?>
<AnchorPane id="AnchorPane" prefHeight="91.0" prefWidth="-1.0" xmlns:fx="http://javafx.com/fxml"> 

[Code] ....

Java:
java version "1.8.0_05"Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) Server VM (build 25.5-b02, mixed mode)

View Replies View Related

Receiving Wrong Minimum Value And Code Is Not Reading File Properly

Feb 11, 2015

My program is reading my file, but its printing out weird cryptic numbers instead of the 1-10 that is in the file. But it uses the numbers in the file to get the Max Value and Total. Also I am receiving 0 for my Minimum Value but, 0 isn't even in the file, my lowest value is 1.

Java Code: /*

* Student Name: Irrelavent
*
* Description: This program will read from a text file and display its contents in an array format as well as the average of the numbers and the minimum and maximum value within the array and it will display the total of all the numbers added together.
*
* Input Variables:
*
* Desired Output:
* Total: 55
Average: 5.5
Minimum Value: 1.0
Maximum Value: 10.0
The data being used is: [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
*/

[Code] ....

Output:

Numbers being used: [[I@55f96302]

---------------
Max Value: 10
---------------
Minimum Value: 0
---------------
Average: 0.0
---------------
Total: 55

I want 1 for my Minimum and I want 5.5 for my average, when I make 'average = total / numbers.length;' ---> 'average = total / (double)numbers.length;' I get 0.55. Also, as its obvious, my 'Numbers being used' section is messed up and I don't know whats causing this.

View Replies View Related

Java Class Date Method Showing Wrong Year

Dec 31, 2013

We use a Java program to read an XML file and put its content into a database. We also use Date() to get the current date and insert it into a field in database with content from XML file. Everything worked flawlessly until today, the last day of 2013. We are getting 2014 for the year instead of 2013!!! System date shows correct year, so this must not be an issue.

View Replies View Related

Difference In Variable Assignment Between Constructor And Variable Section

May 21, 2014

Given the case I have an object which is assigned only once. What is the difference in doing:

public class MyClass {
private MyObj obj = new MyObj("Hello world");

private MyClass(){}
//...
}

and

public class MyClass {
private MyObj obj;
private MyClass(){
obj = new MyObj("Hello world");
}
//...
}

Is there a difference in performance or usability? (Given also the case there are no static calls expected) ....

View Replies View Related

Are Terms Local Variable And Member Variable Comparable

Oct 27, 2014

The term "Local variable" is related to scope. That is a local variable is one which is defined in a certain block of code, and its scope is confined inside that block of code.And a "Member variable" is simple an instance variable.

I read in a discussion forum that when local variables are declared (example code below), their name reservation takes place in memory but they are not automatically initialized to anything. On the other hand, when member variables are declared, they are automatically initialized to null by default.

Java Code: public void myFunction () {
int [] myInt; // A local, member variable (because "static" keyword is not there) declared
} mh_sh_highlight_all('java');

So it seems that they are comparing local variables and member variables. While I think a member variable can also be be local in a block of code, isn't it?

View Replies View Related

Program To Read / Compare Time Intervals - Showing Wrong Output

Feb 24, 2015

the below program is to read the time intervals (HH:MM) and to compare system time if the system time between your time intervals print correct time and exit else try again to repeat the same thing. By using StringToknizer class. and i have written like this

import java.io.*;
import java.util.*;
public class Main
{
static int k1,k2,v1,v2;
public static void main(String args[]) throws IOException
{
DataInputStream o=new DataInputStream(System.in);

[Code] ....

but is showing correct for some inputs and wrong for some inputs ....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved