Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

Java - Calculator

General description for homework: In this homework, you need to modify the java source code file Calculator.java in chap 9, so that it takes the input parameter in a different way. For example, instead of taking one parameter "7 + 20" as the only argument, the modified version takes three parameters 7 + 20 as the argument list for the main method, and perform the same task of calculating the result for the expression. Here is the detail description for homework 9: No GUI is needed in this homework. No console input is needed, thus no need to import Scanner class. In the main method, then follow the STEPS below:

1. If the number of arguments supplied to the main method is not equal to 3, then output a line that says "Usage: java operand1 operator operand2" , and then quit the program. The program continues to the following steps if the argument number is 3.

2. If the second parameter is none of the following: + , -, x, / , %, then you need to output a line that says: "supported operators are +, -, x, / , and % " , and then quit the program. The symbol x above means multiplication. Attention: we CANNOT use symbol * as multiplication in our homework, and the reason is explained in the "Implementation requirement" below.

3. If the second parameter is any one of the following: + , -, x, / , %, then convert the first and the third parameter to int type, and then perform the required calculation. Save the calculated result to a local variable, and the result should be of int type.

4. Output to the console with the entire expression and calculated result , such as 7 + 20 = 27 Implementation requirement:

• In class java, you should have only one method: the main method. Do not put more classes or more methods in the homework, o/w, you are in the wrong track.

• User Calculator.java as a reference, and feel free to invoke APIs from String/StringBuilder.

• Notice that if the operator is / , and the result is int type, that means the division precision will not be kept. For example, 13 /3 will yield a result of 4.

• Notice that we use symbol x for multiplication operation, and this is different from textbook source code "Calculator.java" that uses symbol * for multiplication. We CANNOT use symbol * for multiplication in this homework, because symbol * has special meaning in command line, when symbol * itself is supplied as an individual String object in the command line.

• Symbol % means the remainder operator, and you can refer to textbook page 46 for explanation of remainder operator.

• Add suitable comments in the source code.

• Please read the above implementation details carefully BEFORE start coding.

• After finishing coding, you need to debug your program and test it multiple times with different input parameters provided for each test run.

• You can use command line to supply the arguments and test the program, or use Eclipse. Either way is fine.

Java, Programming

  • Category:- Java
  • Reference No.:- M92183966

Have any Question?


Related Questions in Java

Solving 2nd degree equationsbull write the following java

Solving 2nd degree equations • Write the following Java methods • boolean real-sols(double a, double b, double c): it returns true if the 2nd degree equation ax2 + bx + c has real solutions • double solution1(double a, d ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Part a specification - robot simulationpart a

PART A Specification - Robot Simulation PART A Requirements To complete this assignment you will use the supplied eclipse project Robot P1/. It is already set up to execute a simple arm movement loop which you will build ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Assignment - method in our madnessthe emphasis for this

Assignment - "Method in our Madness" The emphasis for this assignment is methods with parameters. In preparation for this assignment, create a folder called Assign_3 for the DrJava projects for the assignment. A Cityscap ...

Question slideshows or carousels are very popular in

Question : Slideshows (or carousels) are very popular in websites. They allow web developers to display news or images on the website in limited space. In this code challenge, you are required to complete the JavaScript ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

Can someone please help me with the following java

can someone please help me with the following java question The input is an N by N matrix of nonnegative integers. Each individual row is a decreasing sequence from left to right. Each individual column is a decreasing s ...

Can someone kindly help me to consider whether java

Can someone kindly help me to consider whether Java provides the facility of operator overloading? If it does, may you kindly describe how overloading operators can be accomplished? If not, may you kindly describe why yo ...

Operating systems assignment -problem 1 sharing the bridgea

Operating Systems Assignment - Problem 1: Sharing the Bridge A new single lane bridge is constructed to connect the North Island of New Zealand to the South Island of New Zealand. Farmers from each island use the bridge ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As