wood burning stoves 2.0
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Any ideas about errors" Watch "Any ideas about errors" New topic

Any ideas about errors

ezekiel diligene

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....

fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11956

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

Joined: Oct 01, 2001
Posts: 2969

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

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...
I agree. Here's the link: http://aspose.com/file-tools
subject: Any ideas about errors
It's not a secret anymore!