shadylookin
10-01-2006, 09:32 PM
I am new to java and have a question.
public class USDollars {
private int dollars;
private int cents;
private int increase;
public USDollars(int dollars, int cents, int increase){
this.dollars = dollars;
this.cents = cents;
this.increase = increase;
}
public int add(){
fixedCents = cents + increase;
if (fixedCents > 99){
dollars + 1;
fixedCents-100;
}
}
public String toString(){return dollars+"."+fixedCents;}
}
I want to be able to allow for an increase in cents, but obviously I don't want people to be able to have 15dollars and 190cents because that's just not how it is supposed to be. can anyone give me some tips on how to properly express adding to dollars and subtracting to cents when my cents > 99?
also eclipse is giving me an error when i try and add fixedCents in my toString method. How do i write it so that I get the fixedCents variable from the add method?
Thanks for your time and help
public class USDollars {
private int dollars;
private int cents;
private int increase;
public USDollars(int dollars, int cents, int increase){
this.dollars = dollars;
this.cents = cents;
this.increase = increase;
}
public int add(){
fixedCents = cents + increase;
if (fixedCents > 99){
dollars + 1;
fixedCents-100;
}
}
public String toString(){return dollars+"."+fixedCents;}
}
I want to be able to allow for an increase in cents, but obviously I don't want people to be able to have 15dollars and 190cents because that's just not how it is supposed to be. can anyone give me some tips on how to properly express adding to dollars and subtracting to cents when my cents > 99?
also eclipse is giving me an error when i try and add fixedCents in my toString method. How do i write it so that I get the fixedCents variable from the add method?
Thanks for your time and help