hello again, i hate to be a bother but this is the third day im working on this assignment and i need a little help ill point out the 2 lines im having trouble with in my driver program(driver1) but ill supply you with the class definition and the driver program:

public class Money
{
	private int dollars;//instance variables
	private int cents;
	
	public Money(int d, int c)//constructor with two parameters for dollars and cents
	{
		dollars = d;
		cents = c;
	}
	
	public Money(int da)//constructor with one parameter for dollars
	{
		dollars = da;
		cents = 0;
	}
	
	public Money()//no-argument constructor
	{
		dollars = 0;
		cents = 0;
	}
	
	public static Money add(Money m3, Money m4)//static method for addition
	{
		int dollars1 = m3.getDollars();
		int dollars2 = m4.getDollars();
		int cents1 = m3.getCents();
		int cents2 = m4.getCents();
		int sumDollars = dollars1 + dollars2;
		int sumCents = cents1 + cents2;
		
		if(sumCents >= 100)
		{
			sumDollars = sumDollars + 1;
			sumCents = sumCents - 100;
		}
		
		Money output = new Money(sumDollars, sumCents);
		return output;
	}
	
	public static Money minus(Money m1, Money m2)//static method for subtraction
	{
		int dollars1 = m1.getDollars();
		int dollars2 = m2.getDollars();
		int cents1 = m1.getCents();
		int cents2 = m2.getCents();
		int minusDollars = dollars1 - dollars2;
		int minusCents = cents1 - cents2;
		
		Money output1 = new Money(minusDollars, minusCents);
		return output1;
	}
	
	public void add2(Money a)//method using calling object for addition
	{
		int dollars1 = this.getDollars();
		int dollars2 = a.getDollars();
		int cents1 = this.getCents();
		int cents2 = a.getCents();
		int sumDollars = dollars1 + dollars2;
		int sumCents = cents1 + cents2;
		
		if(sumCents >= 100)
		{
			sumDollars = sumDollars + 1;
			sumCents = sumCents - 100;
		}
		
		this.setDollars(sumDollars);
		this.setCents(sumCents);
	}
	
	public void minus2(Money c)//method using calling object for subtraction
	{
		int dollars1 = this.getDollars();
		int dollars2 = c.getDollars();
		int cents1 = this.getCents();
		int cents2 = c.getCents();
		int minusDollars = dollars1 - dollars2;
		int minusCents = cents1 - cents2;
		
		this.setDollars(minusDollars);
		this.setCents(minusCents);
	}
	
	public int getDollars()//accessor method to get dollars
	{
		return dollars;
	}
	
	public int getCents()//accessor method to get cents
	{
		return cents;
	}
	
	public void setDollars(int dol)//mutator method to set amount of dollars
	{
		dollars = dol;
	}
	
	public void setCents(int cen)//mutator method to set amount of cents
	{
		cents = cen;
	}
	
	public String toString()//toString method
	{
		return ("$" + getDollars() + "." + getCents());
	
	}
	
	public boolean equals(Money yourMoney)//equals method
	{
		return ((this.dollars==yourMoney.dollars)&&(this.cents==yourMoney.cents));
	}
}
import java.util.Scanner;

public class driver1
{
	public static void main(String[] args)
	{
		Scanner keyboard = new Scanner(System.in);
		Money ok = new Money();
		System.out.println("Enter another dollar value.");
		ok.setDollars(keyboard.nextInt());
		System.out.println("Enter another cents value.");
		ok.setCents(keyboard.nextInt());
		
		Money ok_1 = new Money();
		System.out.println("Enter another dollar value.");
		ok_1.setDollars(keyboard.nextInt());
		System.out.println("Enter another cents value.");
		ok_1.setCents(keyboard.nextInt());
		
		System.out.println("Added: " + ok.add2(ok_1));
		System.out.println("Subtracted: " + ok.minus2(ok_1));
		
		Money good = new Money();
		System.out.println("Enter a dollar amount.");
		good.setDollars(keyboard.nextInt());
		System.out.println("Enter a cents amount.");
		good.setCents(keyboard.nextInt());
		
		Money bad = new Money();
		System.out.println("Enter a dollar amount.");
		bad.setDollars(keyboard.nextInt());
		System.out.println("Enter a cents amount.");
		bad.setCents(keyboard.nextInt());
		
		System.out.println("Added: " + Money.add(good, bad));
		System.out.println("Subtracted: " + Money.minus(good, bad));
		
		if(good.equals(bad))
		{
			System.out.println("The same.");
		}
		else
		{
			System.out.println("Different.");
		}
	}
}

in my driver program im having trouble where it says ok.add2(ok_1) which calls my add2 method to add the two objects
same with the minus2 in the next line
the compiler message is as follows for those two lines:void type not allowed here
can anyone help me make this work
thank you for your help

Hey javaman2,

What happens with your program if you have $10.30 minus $5.60? What result do you get?

add2 method is void. So it doesn't return anything. It just adds the argument to the Money object calling it.
When you call it, as you can see, it adds the argument to the dollars and cents of the object that made the call.

Also your minus algorithm is wrong as pointed out by darkagn

This question has already been answered. Start a new discussion instead.