0% found this document useful (0 votes)
6 views

CS111_Homework - A Simple Calculator Program

The document outlines an assignment for a simple calculator program in Java for a CS111 course. It includes a declaration of originality, assignment requirements, and specific programming tasks such as creating methods for various mathematical operations and implementing user input handling. The assignment aims to assess students' understanding of fundamental programming constructs and problem-solving techniques.

Uploaded by

faal5532
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

CS111_Homework - A Simple Calculator Program

The document outlines an assignment for a simple calculator program in Java for a CS111 course. It includes a declaration of originality, assignment requirements, and specific programming tasks such as creating methods for various mathematical operations and implementing user input handling. The assignment aims to assess students' understanding of fundamental programming constructs and problem-solving techniques.

Uploaded by

faal5532
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

CS111-Homework

A Simple Calculator Program

Assignment Submission Declaration


By submitting this work and signing this document, I declare that:
1. This assignment is my own original work.
2. No part of this work has been copied from any other source or person except where explicitly stated
otherwise by reference or acknowledgment.
3. No part of this work has been previously submitted for assessment at this or any other institution.
4. I may be subject to student discipline processes in the event of an act of academic misconduct by me
including an act of plagiarism or cheating.
Course Code CS111
Course Title Programming 1
Student ID
Student Name
Signature of Student
Date of Signature

Marks (to be filled by the course instructor)


CLOs Question # Assigned Gained Comments
Mark Mark
2.2 2
Q1
4.2 1
Average 3

Create computer programs in the selected language based on fundamental programming


CLO2.2 constructs: basic computation, simple I/O, standard conditional and iterative structures, the
definition of functions and arrays.

CLO4.2 Use mathematical or statistical techniques for solving problems

1
Q1. Write a Java program for a simple calculator of the operations: Addition, Subtraction,
Multiplication, Division, and Exponent values (i.e. power-of). The program must satisfy the
following requirements:
(1) Declare an integer variable for the operation choice (opChoice) and three double variables
for first and second numbers (num1, num2) and the result of operation (result);
(2) Ask the user to enter the operation (opChoice) he/she wants to perform: 1 for Addition, 2 for
Subtraction, 3 for Multiplication, 4 for Division, and 5 for Exponent value;
(3) Create a method for each operation: add(), subtract(), multiply(), divide(), power(); Each
method returns a double value and takes num1, num2 as arguments; and get the numbers for
num1 and num2 randomly (0 to 10 inclusive); In subtract() and divide() methods, swap num1
and num2 if num1 < num2; In the power() method, calculate num1 to the power of num2;
(4) Use a while block so that the user can see the results of multiple operations of Addition,
Subtraction, Multiplication, Division and/or Exponent. This loop keeps asking the user to
enter his option for the next operation, and only stops if opChoice is less than 1 or greater
than 5;
(5) Inside the while block, use a switch-case block to do the calculations calling the right
corresponding method, such that case 1 calls add(), case 2 calls subtract(), case 3 calls
multiply(), case 4 calls divide(), and case 5 calls power();

The program must show the inputs and outputs according to the given sample below:

2
The Program Source Code:

3
The Program Outputs Snapshot Copied from NetBeans:

You might also like