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)
- Java source code (Money.java and MoneyTester.java).
- Output of the sample run
Trending nowThis is a popular solution!
Step by stepSolved in 7 steps with 3 images
- JAVA METHOD OVERLOADINGarrow_forwardMath 130 Java programming Dear Bartleby, I am a student beginning in computer science. May I have some assistance on this lab assignment please? Thank you.arrow_forwardCan you please help me with this, its in java. Thank you. Write classes in an inheritance hierarchy Implement a polymorphic method Create an ArrayList object Use ArrayList methods For this, please design and write a Java program to keep track of various menu items. Your program will store, display and modify salads, sandwiches and frozen yogurts. Present the user with the following menu options: Actions: 1) Add a salad2) Add a sandwich3) Add a frozen yogurt4) Display an item5) Display all items6) Add a topping to an item9) QuitIf the user does not enter one of these options, then display:Sorry, <NUMBER> is not a valid option.Where <NUMBER> is the user's input. All menu items have the following: Name (String) Price (double) Topping (StringBuilder or StringBuffer of comma separated values) In addition to everything that a menu item has, a main dish (salad or sandwich) also has: Side (String) A salad also has: Dressing (String) A sandwich also has: Bread type…arrow_forward
- JAVA PROGRAM Chapter 7. PC #1. Rainfall Class Write a RainFall class that stores the total rainfall for each of 12 months into an array of doubles. The program should have methods that return the following: • the total rainfall for the year • the average monthly rainfall • the month with the most rain • the month with the least rain Demonstrate the class in a complete program. Main class name: RainFall (no package name) HERE IS A WORKING CODE, PLEASE MODIFY THIS CODE SO THE PUBLIC CLASS IS MAIN AND WERE EVER THERE IS MAIN IN THE CHANGE IT SO IT RUNS. ALSO, MAKE SURE WHEN I UPLOAD THE CODE TO HYPERGRADE IT PASSES ALL THE TEST CASES. THANK YOU import java.util.Scanner;public class Main { private double[] rainfall = new double[12]; public Main(double[] rainfall) { this.rainfall = rainfall; } public double getTotalRainfall() { double total = 0.0; for(double rain : rainfall) { total += rain; }…arrow_forwardIn C++ class rectangleType { public: void setLengthWidth(double x, double y); //Sets the length = x; width = y; void print() const; //Output length and width double area(); //Calculate and return the area of the rectangle (length*width) double perimeter(); //Calculate and return the perimeter (length of outside boundary of the rectangle) private: double length; double width; }; Print out the area of the rectangle.arrow_forwardJavaarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education