I'm trying to get my program to take coins out of the purse, but it keeps adding them:
public class Purse
{
private int pennies;
private int nickels;
private int dimes;
private int quarters;
public void purse ()
{
pennies = 0;
nickels = 0;
dimes = 0;
quarters = 0;
}
public void addPennies (int count)
{
pennies = pennies + count;
}
public void addNickels (int count)
{
nickels = nickels + count;
}
public void addDimes (int count)
{
dimes = dimes + count;
}
public void addQuarters (int count)
{
quarters = quarters + count;
}
public void delPennies (int count)
{
pennies = count - pennies;
}
public void delNickels (int count)
{
nickels = count - nickels;
}
public void delDimes (int count)
{
dimes = count - dimes;
}
public void delQuarters (int count)
{
quarters = count - quarters;
}
public double calculateTotal ()
{
return (pennies*.01)+(nickels*.05)+(dimes*.10)+(quarters*.25);
}
}
import javax.swing.JOptionPane;
public class InputTest3 {
public static void main (
String[]args) {
Purse myPurse = new Purse ();
String input = JOptionPane.showInputDialog("How many pennies do you have?");
int count = Integer.parseInt(input);
myPurse.addPennies(count);
input = JOptionPane.showInputDialog("How many nickels do you have?");
count = Integer.parseInt(input);
myPurse.addNickels(count);
input = JOptionPane.showInputDialog("How many dimes do you have?");
count = Integer.parseInt(input);
myPurse.addDimes(count);
input = JOptionPane.showInputDialog("How many quarters do you have?");
count = Integer.parseInt(input);
myPurse.addQuarters(count);
input = JOptionPane.showInputDialog("How many pennies do you want to take out?");
count = Integer.parseInt(input);
myPurse.delPennies(count);
input = JOptionPane.showInputDialog("How many nickels do you want to take out?");
count = Integer.parseInt(input);
myPurse.delNickels(count);
input = JOptionPane.showInputDialog("How many dimes do you want to take out?");
count = Integer.parseInt(input);
myPurse.delDimes(count);
input = JOptionPane.showInputDialog("How many quarters do you want to take out?");
count = Integer.parseInt(input);
myPurse.delQuarters(count);
double totalValue = myPurse.calculateTotal ();
System.out.println("The total is " + totalValue);
}
}
Any ideas? I'm pretty stuck here.