Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In Java: I need help with step 2 and step 5. Step 5 is just more methods to step 2 (which was answered previously). Before
In Java:
I need help with step 2 and step 5. Step 5 is just more methods to step 2 (which was answered previously).
Before you turn in your work: use the Java Style Guide to document your project. (10 pts) Step 1: Create an IntelliJ project named ChangeJarPrj Create a package named: changeJarPack (right click on ChangeJarPrj and select new/package) Create a class named: Changejar (right click on change JarPack and select new/class) o The properties and methods for this class are in step 2. You will find some starter code on github. Create a JUnit Test Case named: Change JarTest (Right click on ChangeJar, if you have questions, see the instructor) O You'll find some starter code on github for this as well. Step 2: Implement the following methods for the class ChangeJar: Implement the following methods and properties in Changejar 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 ChangeJar. 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 Change Jar 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: "1.3 is 5 quarters, 1 nickel 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 Changejar 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 ChangeJar object jarl is exactly the same (in terms of amount in the Change Jar) as if ChangeJar object jar2. public int compare to (Changejar other) A method that returns 1 if this Change Jar object is greater than (based upon the total in the Charge Jar) 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 Change Jar 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 Change Jar 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 Change Jar object jar2. public void subtract (int quarters, int dimes, int nickels, int pennies) A method that subtracts the parameters from the "this Change Jar 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" Change Jar by 1 penny. public void add (int quarters, int dimes, int nickels, int pennies) A method that adds the parameters from the "this" Change Jar 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 Change Jar by 1 penny. public String toString() Method that returns a string that represents a Change Jar 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 5: Create the following additional methods in the Changejar class: public void save (String fileName) A method that saves the this ChangeJar to a file; use the parameter filename for the name of the file. public void load (String fileName) A method that loads the this ChangeJar object from a file; use the parameter filename for the name of the file. public Changejar takeout (double amount) Take out amount using the available quarters, dimes, nickels and pennies. For example: 1.23 would be 4 quarters, 2 dimes, 3 pennies. Example 2. The Changejar holds 4 quarters, 3 dimes, 0 nickels, 3 pennies; now takeout(.80) which would be 2 quarters and 3 dimes. If it is not possible to take out the requested amount (not enough or cannot make the amount with the available coins), return null. O This sounds easy, it is not. public static void Mutate (Boolean on) A method that turns off (false) and on' (true) any subtract/add methods in ChangeJar based on the value (true,false) of the variable on'. In other words, when on is false, this prevents any subtract/add method from changing (mutate) the state of the this object as it relates to the amount in the Change Jar. A change from step 2; allow for an error in the input arguments for all constructors and methods, and throw an IllegalArgumentException exception if an error occurs. For example, "-1.23 is not a valid input string for a constructor in step 2 and an exception is thrown. o Sample code snippet many help: if (amountStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started