Hey, I'm taking an AP Comp Sci class in High school and we're learning Java, and this is my first try at programming. We have an assignment to do... here are the instructions:
Now here is what I have. I think it's right, but if not let me know. I keep on getting errors when trying to compile.
The errors that are coming up are "identifier expected" on line 61
And it also says it needs a ")" on line 77
Create your own PiggyBank class. This class will be used to create PiggyBank objects; therefore, everyone can have their own piggy bank! When your personal bank is created (instantiated), it may be stuffed with a certain number of pennies, nickels, dimes, and quarters. You will be able to access the number of each type of coin deposited into the bank as well as the banks total dollar value. You will also need to create methods that will allow the piggy bank to receive coins and update the appropriate values.
Now here is what I have. I think it's right, but if not let me know. I keep on getting errors when trying to compile.
Code:
public class PiggyBank {
private int pennies;
private int nickels;
private int dimes;
private int quarters;
/** Creates a new instance of PiggyBank */
public PiggyBank(int findPennies, int findNickels, int findDimes, int findQuarters) {
pennies = findPennies;
nickels = findNickels;
dimes = findDimes;
quarters = findQuarters;
}
public int getPennies()
{
return pennies;
}
public int getNickels()
{
return nickels;
}
public int getDimes()
{
return dimes;
}
public int getQuarters()
{
return quarters;
}
public void setPennies(int newPennies)
{
pennies = newPennies;
}
public void setNickels(int newNickels)
{
nickels = newNickels;
}
public void setDimes(int newDimes)
{
dimes = newDimes;
}
public void setQuarters(int newQuarters)
{
quarters = newQuarters;
}
public static void main (Stringargs[])
{
PiggyBank myPiggyBank = new PiggyBank(20, 10, 5, 12);
System.out.println("There are" +myPiggyBank.getPennies() +"pennies.");
System.out.println("There are" +myPiggyBank.getNickels() +"nickels.");
System.out.println("There are" +myPiggyBank.getDimes() +"dimes.");
System.out.println("There are" +myPiggyBank.getQuarters() +"quarters.");
myPiggyBank.setPennies(30);
myPiggyBank.setNickels(20);
myPiggyBank.setDimes(15);
myPiggyBank.setQuarters(22);
System.out.println("Now there are" +myPiggyBank.getPennies() +"pennies.");
System.out.println("Now there are" +myPiggyBank.getNickels() +"nickels.");
System.out.println("Now there are" +myPiggyBank.getDimes() +"dimes.");
System.out.println("Now there are" +myPiggyBank.getQuarters() +"quarters.");
}
}
The errors that are coming up are "identifier expected" on line 61
And it also says it needs a ")" on line 77