Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java, Implement the following methods and properties in Change Jar class. For properties, you will need four instance variables: quarters (integer), dimes (integer), nickels

In Java, image text in transcribedimage text in transcribed

Implement the following methods and properties in Change Jar class. For properties, you will need four instance variables: quarters (integer), dimes (integer), nickels (integer), pennies (integer). There are no dollars bills (or dollar coins) in this Change Jar. For methods, you will need to implement the following (include any setters or getters that are needed). Unless otherwise stated, you can assume the input has no errors for step 2 (i.e., a valid set of numbers) contained within (later steps this does not apply). public ChangeJar() Default constructor that sets the Change Jar to zero. public ChangeJar (double amount) A constructor that initializes the instance variables with the provided value converted to quarters, dimes, nickels, and pennies. For example, if amount was 1.34 then you would have 5 quarters, 1 nickel, 4 pennies. Page public Changejar (ChangeJar other) A constructor that initializes the instance variables with the other ChangeJar parameter. public ChangeJar (String amount) A constructor that accepts a string as a parameter with the provided value converted to quarters, dimes, nickels, and pennies. For example, if amount was 1.34" then you would have 5 quarters, 1 nickel, 4 pennies. More examples: o 1.3 is 5 quarters, 1 nickel o 1.34 is 5 quarters, 1 nickel, 4 pennies O "0.34 is 34 cents; 1 quarter, 1 nickel, 4 pennies O "0.04 is 4 cents o "500. is not allowed, instead "500.0 is used. public boolean equals (Object other) A method that returns true if this Change Jar object is exactly the same (in terms of the amount in the Change Jar) as the other object (Note: you must cast the other object as a Change Jar object). public static boolean equals (ChangeJar jari, ChangeJar jar2) A static method that returns true if Change Jar object jarl is exactly the same (in terms of amount in the Change Jar) as if Change Jar object jar2. public int compareTo (ChangeJar other) A method that returns 1 if this Change Jar object is greater than (based upon the total in the ChargeJar) the other Change Jar object; returns -1 if the "this Change Jar object is less than the other Change Jar; returns 0 if the this Change Jar object is equal to the other ChangeJar object. public static int compareTo (ChangeJar jari, Change Jar jar2) A method that returns 1 if Change Jar object jarl is greater (in terms of the amount in the Change Jar) than ChangeJar object jar2; returns -1 if the Change Jar object jarl is less than Change Jar jar2; returns 0 if the Change Jar object jarl is equal to ChangeJar object jar2. public void subtract(int quarters, int dimes, int nickels, int pennies) A method that subtracts the parameters from the this ChangeJar object. You may assume all of the parameter are positive. public void subtract (Changejar other) A method that subtracts Change Jar other to the this Change Jar object. (For step 2 there are no worries about errors) public void dec (). A method that decrements the this ChangeJar by 1 penny. public void add (int quarters, int dimes, int nickels, int pennies) A method that adds the parameters from the this ChangeJar object. You may assume all of the parameter are positive. public void add (Changejar other) A method that add ChangeJar other to the this Change Jar object. public void inc() A method that increments the this ChangeJar by 1 penny. public String toString() Method that returns a string that represents a ChangeJar with the following format: 10 quarters, 1 dime, 0 nickels, 1 penny. Be sure to use proper pluralization. For example, 1 penny or 2 pennies

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

Recommended Textbook for

More Books

Students also viewed these Databases questions