Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

java question. write program. help to undersand it. Do not work w/ paper!!!! i n

ID: 3869572 • Letter: J

Question

java question. write program.

help to undersand it.

Do not work w/ paper!!!! i need code that copiable w/ eclipse program.

Define a class named Money that stores a monetary amount. The class should have two private integer variables, one to store the number of dollars and another to store number of cents. Add accessor and mutator methods to read and set both member variables. Add another method that returns the monetary amount as double. Write a program that tests all of your functions with at least two different money objects.

Explanation / Answer

// Class Money

public class Money {

private int dollar;

private int cents;

public int getDollar() {

return dollar;

}

public void setDollar(int dollar) {

this.dollar = dollar;

}

public int getCents() {

return cents;

}

public void setCents(int cents) {

this.cents = cents;

}

public double getMoney() {

double money = dollar;

money += ((double)cents/100);

return money;

}

}

// Class with main Method to test functionalities

public class TestMoney {

public static void main(String[] args) {

Money money = new Money();

Money money2 = new Money();

money.setDollar(2);

money.setCents(58);

money2.setDollar(money.getDollar());

money2.setCents(money.getCents());

double doubleMoney1 = money.getMoney();

System.out.println(doubleMoney1);

doubleMoney1 = money2.getMoney();

System.out.println(doubleMoney1);

}

}