Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a class encapsulating the concept of money, assuming that money has the following attributes: dollars, cents In addition to the constructors, the accessors and

Write a class encapsulating the concept of money, assuming that money has the following attributes: dollars, cents

In addition to the constructors, the accessors and mutators, write the following methods:

public Money()

public Money(int dollars, int cents)

public Money add(Money m)

public Money substract(Money m)

public Money multiply(int m)

public static Money[] multiply(Money[] moneys, int amt)

public boolean equals(Money money)

public String toString()

private void normalize() // normalize dollars and cents field

_____h_____e_______r________e______________i_____s___________the _____________tester class_______________

public class MoneyTester

{

public static void main(String[] args)

{

Money m1 = new Money(8, 75); // set dollars to 8 and cents to 75

Money m2 = new Money(5, 80); // set dollars to 5 and cents to 80 Money

Money m3 = new Money(); // initialize dollars to 0 and cents to 0

System.out.println("\tJane Doe " + "CIS35A Fall 2019 Lab 4"); // use

your name

System.out.println("m1 = " + m1);

System.out.println("m2 = " + m2);

System.out.println("m3 = " + m3);

System.out.println("m1 equals m2? " + m1.equals(m2));

System.out.println("m1 equals m3? " + m1.equals(m3));

Money m4 = m1.add(m2);

System.out.println("m4 = m1 + m2 = " + m1.add(m2));

Money m5 = m4.multiply(3);

System.out.println("m5 = m4 * 3 = " + m5);

System.out.println("m1 + m2 + m3 + m4 = " +

m1.add(m2).add(m3).add(m4));

Money[] m6 = new Money[]{new Money(10, 50), new Money(20, 50), new

Money(30, 50), new Money(40, 50)};

Money[] m7 = Money.multiply(m6, 2);

System.out.print("m6 = (");

for(int i = 0; i

{

if(i

System.out.print(m6[i] + ", ");

else

System.out.print(m6[i] + ")");

}

System.out.println();

System.out.print("m7 = m6 * 2 = (");

for(int i = 0; i

{

if (i

System.out.print(m7[i] + ", ");

else

System.out.print(m7[i] + ")");

}

System.out.println();

}

}

_______________output will look like this_____________________________________________________________

image text in transcribed

E E E E Jane Doe CIS35A Fall 2019 Lab 4 ml = 8.75 m2 = 5.80 m3 = 8.75 m1 equals m2? false ml equals m3? true m4 = ml + m2 = 14.55 m5 = m4 * 3 = 43.65 m1 + m2 + m3 + m4 = 37.85 m6 = (10.50 20.50, 30.50, 40.50) m7 = m6 * 3 = (21.0, 41.0, 61.0, 81.0) E E E E E

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions