Starting from:
$30

$24

MP 1 Java Basics Solution

Introduction



Please read all sections of this document before you begin coding. The purpose of this machine problem is to familiarize you with the basics of Java programming. You will code, compile and demo a simple calculator on your laptop.




Problem Statement



In this assignment, implement a calculator that performs the operations of addition, subtraction and multi-plication.




Classes




You must create a class called Calculator




Fields




p r i v a t e S t r i n g name




Methods




p u b l i c p u b l i c p u b l i c p u b l i c p u b l i c




F l o a t a d d i t i o n ( F l o a t A, F l o a t B)




F l o a t s u b t r a c t i o n ( F l o a t A, F l o a t B)




F l o a t m u l t i p l i c a t i o n ( F l o a t A, F l o a t B)




v o i d setname ( S t r i n g N)




S t r i n g getname ( )



Operation



Under the main method, a new Calculator object called mycalc must be created. setname method to set your group number (eg. Group 5) as the name of mycalc. out the following line (using the getname method):




In your code, call the The system must print



Welcome t o
t h e
C a l c u l a t o r d e s i g n e d
by " mycalc . name " .
Enter A t o
Add ,
S t o S u b t r a c t , M t o
M u l t i p l y , and Q t o q u i t .
Parse the input as a String and then output


Enter
argument
1


Enter
argument
2





In each case above, wait for an input, parse each input as a String, and then convert to Float. Call the appropriate method on mycalc. Print out the answer using the format




The sum/ d i f f e r e n c e / p r o d u c t o f argument 1 and argument 2 i s answer




Put the whole code in a while loop, and terminate when Q is entered. Any other inputs should return the user to the Welcome message.






1









Evaluation Guidelines



Check the operation using test values.



Check the code to verify class de nitions



Enter arbitrary strings to test for error handling.



References




[1] Head First Java. Chapters 1-5.























































































































































2

More products