This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Any ideas about errors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Any ideas about errors" Watch "Any ideas about errors" New topic
Author

Any ideas about errors

ezekiel diligene
Greenhorn

Joined: Dec 01, 2005
Posts: 5
class CarPark1
{
// private instance variables
private int Payment, total, balance;

// public no-argument constructor
public CarPark1() { }

// public constructor with three arguments
public CarPark1(int p, int t, int b)
{
payment = p;
total = t;
balance = b;
}

// public 'set' methods
public void setPayment(int p) { payment = p; }
public void setTotal(int total) { total = t; }
public void setbalance(int balance) { balance = b; }

// public method to calculate the total
public int calculateTotal()
{
int balance = total - payment;
// more code here to show balance =>0 message displayed
return balance;
}
}


Any advice would be much appreciated. I'm fairly new at this....


b.notes
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11170
    
  16

help us help you. what exact errors are you getting? what are you expecting to see?

also, if you'd use the code tags, it'd preserve your formatting, and make your code easier to read. use those "instant UBB" buttons to get the tags, then paste your formatted code between them.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2841
    
  11

One problem is you declare an instance variable as Payment, then use it as payment. Java variables are case sensitive, and by convention should always start with a lowercase letter.
Srinivas Kumar
Ranch Hand

Joined: Jul 14, 2005
Posts: 52
Also u haven't declared the variable t in the method setTotal().
Same is the case with the variable b in setbalance() method.
ezekiel diligene
Greenhorn

Joined: Dec 01, 2005
Posts: 5
thanks so much for all your assistance .. I'll be back to let you knoew the results Cheers Guys...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Any ideas about errors
 
Similar Threads
Program like ATM where person enters amount in dollars and cents but program uses int for monies
Mortgage Calculator and GUI
Illegal start?
cannot resolve symbol
Having trouble understanding an error code i keep getting. Please help!