Question: If you could comment code and do the extra credit I will make sure to upvote. Thank you. CSC 229 Object Oriented Programming Assignment 3

 If you could comment code and do the extra credit I

will make sure to upvote. Thank you. CSC 229 Object Oriented Programming

Assignment 3 Creating a Calculator Class Due date: Monday 03/06 before midnight

If you could comment code and do the extra credit I will make sure to upvote. Thank you.

CSC 229 Object Oriented Programming Assignment 3 Creating a Calculator Class Due date: Monday 03/06 before midnight Introduction In this homework assignment, you will practice - Creating a class - Constructor overloading (defining more than one constructor) - Instantiating a class you created (creating an object) from within another class - Working with while loops - String comparisons - Reading input Submission Submit your assignment on GitHub. Use the following GitHib Classroom assignment link to accept the assignment and create a GitHub repository. Resources: - Read Chapter 7 on how to define and use a class - Review Section 5.1 on while loops - Refer to Section 4.11 for useful String comparison methods - You might also find the following String methods useful: 1) Build a class called Calculator that emulates basic functions of a calculator: add, subtract, multiply, divide, and clear. The class has one private member field/data aattribute, double value, for the calculator's current value. Implement the following Constructor and instance methods as listed below: - public Calculator() - Constructor method to set the member field to 0.0 - public Calculator (double val) - Constructor method to set the member field to val - public void add (double val) - add val to the member field - public void subtract (double val) - subtract val from the member field - public void multiply (double val) - multiply the member field by val - public void divide (double val) - divide the member field by val - public void clear ( ) - set the member field to 0.0 - public void setvalue (double val) - set the member field to val - public double getvalue ( ) - return the member field 2) Build a program that uses Calculator. Your program should do the following: - Creates a Calculator object and sets the value of its member field to 0 . - Prints a help message to the user with the commands the user can enter - Iteratively (use a while loop) to accept user commands and execute them by calling the appropriate Calculator methods. The program should accept the following commands a) Set - sets the current value in the Calculator object to the user entered number b) Add - add the user entered number to the current value in the Calculator object c) Subtract - subtracts user entered number to the current value in the Calculator object d) Multiply - multiply the current value in the Calculator object by the user entered number e) Divide - divide the current value in the Calculator object by the user entered number f) Print - prints the current value in the Calculator object g) Clear - sets the current value in the Calculator object to 0 h) End - terminates the program Notes: - You will need to use only one of the two Calculator constructors in your main program, but you must implement both. - Your program should be case insensitive (ignore case). For example, if the user inputs end, END, or End, the program should terminate. - For simplicity, you can assume user will always enter correct input. Error checking is extra credit. - Close the scanner! Extra Credit: Check for incorrect user input. This could include entering an incorrect command (shown in second sample output), a command argument that is not numeric, or a division argument that is 0. You can think of other possible errors to account for. You might find Scanner.nextLine( )

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!