n Java code: Write the 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 Add additional helper methods if necessary. Use the following test driver program to test your Money 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 Spring 2021 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)); System.out.println("m4 - m2 = " + m4.subtract(m2)); 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 < m6.length; i++) { if(i < m6.length -1) 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 < m7.length; i++) { if (i < m7.length -1) System.out.print(m7[i] + ", "); else System.out.print(m7[i] + ")"); } System.out.println(); } } Your output will look similar to this         Jane Doe CIS35A Fall 2022  Lab 4 m1 = 8.75 m2 = 5.80 m3 = 0.0 m1 equals m2? false m1 equals m3? false m4 = m1 + m2 = 14.55 m5 = m4 * 3 = 43.65 m1 + m2 + m3 + m4 = 29.10 m4 - m2 = 8.75 m6 = (10.50, 20.50, 30.50, 40.50) m7 = m6 * 2 = (21.0, 41.0, 61.0, 81.0) Java source code (Money.java and MoneyTester.java). Output of the sample run

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

In Java code:

Write the 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

Add additional helper methods if necessary.

Use the following test driver program to test your Money 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 Spring 2021 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));
System.out.println("m4 - m2 = " + m4.subtract(m2));
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 < m6.length; i++)
{
if(i < m6.length -1)
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 < m7.length; i++)
{
if (i < m7.length -1)
System.out.print(m7[i] + ", ");
else
System.out.print(m7[i] + ")");
}
System.out.println();
}
}

Your output will look similar to this

        Jane Doe CIS35A Fall 2022  Lab 4
m1 = 8.75
m2 = 5.80
m3 = 0.0
m1 equals m2? false
m1 equals m3? false
m4 = m1 + m2 = 14.55
m5 = m4 * 3 = 43.65
m1 + m2 + m3 + m4 = 29.10
m4 - m2 = 8.75
m6 = (10.50, 20.50, 30.50, 40.50)
m7 = m6 * 2 = (21.0, 41.0, 61.0, 81.0)

  1. Java source code (Money.java and MoneyTester.java).
  2. Output of the sample run

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 7 steps with 3 images

Blurred answer
Knowledge Booster
Function Calling
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education