Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Submit CoinJar.java to model the concept of tracking money in a jar of coins. CoinJar objects will have integer fields to track the number of

Submit CoinJar.java to model the concept of tracking money in a jar of coins.

CoinJar objects will have integer fields to track the number of pennies, nickels, dimes, and quarters, along with the usual mutators, accessors, and constructors. Only positive coin counts are allowed, else an IllegalArgumentException is thrown.

Specifically, create a CoinJar class with

- A constructor with four integer parameters: CoinJar(pennies, nickels, dimes, quarters)

- A no-parameter default constructor, that sets all coin counts to 0.

- Standard Accessors and mutators for all the fields

- A method called getValue, that returns the total dollar value of all the coins in the jar.

- A method called transferFrom that takes another CoinJar object as a parameter. This method transfers all the coins from the other CoinJar to this CoinJar. After the transfer, other CoinJar will have no coins left.

- Add a toString method that returns in string format the total dollar value of this object. For example, "CoinJar($3.45)" will be returned for a CoinJar object with dollar value of 3.45.

Follow my Class submission requirements Class (data structure) Submission Requirementsimage text in transcribed

image text in transcribed

Here's an example client code for the CoinJar class CoinJarClient.java:

public class CoinJarClient { public static void main(String[] args) { CoinJar zero = new CoinJar(); CoinJar one = new CoinJar(392,34,913,381); CoinJar two = new CoinJar(1,2,3,4); CoinJar three = new CoinJar(23,34,65,235); CoinJar four = new CoinJar(39211,434,983,381); System.out.println(zero); // CoinJar($0.0) System.out.println(one); // CoinJar($192.17) System.out.println(two.getPennies()); // 1 System.out.println(three.getNickels()); // 34 System.out.println(four.getValue()); //607.36 zero.setQuarters(400); zero.setDimes(13); zero.transferFrom(two);// CoinJar two should be emptied after the transfer System.out.println(zero.getQuarters()); // 404 System.out.println(two.getQuarters()); // 0 System.out.println(zero); // $102.71 System.out.println(two); // $0.0 try { one.setDimes(-13); // illegal } catch (IllegalArgumentException event) { System.out.println(event.getMessage()); } try { CoinJar another = new CoinJar(-1,-1,-1,-1); // also illegal } catch (IllegalArgumentException event) { System.out.println(event.getMessage()); } } }
Class (data structure) Submission Requirements at Whenever you submit a Java data structure (Class) in this course, you need to follow: 1. The Program Submission Requirements (comments, indents, etc.). 2. Data fields listed at the top of the Class, and they are all private. 3. Fields are not initialized in these private declarations (Java defaults prevail). 4. The only exception to requirements 1-3 above are public static final constants, which never change. 5. Constructors (that's plural) follow the data field specifications, and those initialize all the fields. 6. Always have a default constructor that defines the assumed defaults for all fields (verify if needed). 7. There should be no redundant constructor code; so the multiple argument version is used for others with this() calls. 8. There should be no redundant method code; so a detailed math formula is in one place, then used by others. 9. Accessor methods are grouped together. Mutators are grouped together. There should be no random placements in Class. 10. System.out calls (and other extraneous TODO garbage) is removed. A data structure is a data structure, not a program!!! Remember to cite your references, or better yet, write your own code to avoid plagiarism. See the Student Code of Conduct and Academic Integrity section of the course syllabus Program Submission Requirements A+ These are the requirements for submitting a Java program in this course: 1. The file name matches the Java Class name which starts with an uppercase character. (Note: When you submit the file in Canvas, it is possible that Canvas renames the file by adding a number to your file name. This is unavoidable and you need not worry about it. I will be able to handle it when grading.) 2. The program compiles with one of the Oracle Java compilers (javac.exe) using JDK 8 or later. 3. Import only java. and javax. classes, or other classes specifically covered in the textbook. 4. Never submit specialized IDE-specific code (e.g., from NetBeans) as the instructor might run the program from the command line. 5. Never submit //TODO lines that your IDE (e.g., Eclipse) generates and you failed to do." 6. Put Your name, course, date, and reasons for doing this as comments at the top of the file (/* comments */). This should probably span multiple lines, any style of /** or /* or // is acceptable. Example: /* Your name, CS 210, mm/dd/yyyy, Reasons for doing this */ 7. Using // style, add additional comments to every screen and at the top of every method you write. 8. Properly indent code for Classes, methods, loops, decisions, etc. as described in the textbook, increasing indentation for each set of braces { } meaning only the Class {} is on the far left. 9. Use proper naming conventions for objects using reasonably descriptive names. Classes always start with upper case character (like String) while object identifiers always start lower case (line args). ALL CODE FILES you submit MUST follow the nine guidelines listed above, each is crucial!!! Points will be deducted for not meeting the program submission requirements. A grade of ZERO is automatic if something like your name is not even in the code. I found this GREAT example in the BJP PowerPoint slides

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

Question

Determine the amplitude and period of each function.

Answered: 1 week ago