ECEN424 Fundamentals of Networking MP 1 solved

$30.00

Category: Tags: , , , , You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (5 votes)

1 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.
2 Problem Statement
In this assignment, implement a calculator that performs the operations of addition, subtraction and multiplication.
Classes
You must create a class called Calculator
Fields
p r i v a t e S t ri n g name
Methods
p u bli c Fl o a t a d di ti o n ( Fl o a t A, Fl o a t B)
p u bli c Fl o a t s u b t r a c ti o n ( Fl o a t A, Fl o a t B)
p u bli c Fl o a t m u l t i p l i c a t i o n ( Fl o a t A, Fl o a t B)
p u bli c v oid setname ( S t ri n g N)
p u bli c S t ri n g getname ( )
Operation
Under the main method, a new Calculator object called mycalc must be created. In your code, call the
setname method to set your group number (eg. Group 5) as the name of mycalc. The system must print
out the following line (using the getname method):
Welcome t o the C al c ul a t o r d e si g n e d by ”mycalc . name ” .
Enter A t o Add, S t o Sub t r ac t , M t o Mul tiply , and Q t o q ui 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 oduc 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
3 Evaluation Guidelines
1. Check the operation using test values.
2. Check the code to verify class definitions
3. Enter arbitrary strings to test for error handling.
References
[1] Head First Java. Chapters 1-5.
2