//Java Program for SImple Handy Calculator
import java.util.*;
import java.lang.*;
import java.text.DecimalFormat;//importing for decimal
formats
class calculator
{
static float input1,input2;
public static void main(String[] args)
{
calculate(); //for
calculations
}
public static void calculate()
{
Scanner input=new
Scanner(System.in);
int option=menu();//user choice
input
if(option>=1 &&
option<=5)
{
switch(option)
{
case 1:
add();//addition
break;
case 2:
sub();//subtraction
break;
case 3:
mul();//multiplication
break;
case 4:
div();//division
break;
case 5:
System.exit(0);//exit for the
program
default:
calculate();//if user prompts
for wrong options
}
}
else
{
System.out.println("You are supposed to Select Correct
Options.");
//used to show
the Message to the User
calculate();//to
calculate again
}
}
public static void add()
{
Scanner ai=new
Scanner(System.in);//defining for taking inputs from console
DecimalFormat df = new
DecimalFormat(); //defining for decimal formats for 2 places
df.setMaximumFractionDigits(2);
System.out.println("Enter two
values for Addition");
try{
input1=ai.nextFloat(); //first input from the user
input2=ai.nextFloat(); //second input fro the user
float
result=input1+input2;
System.out.print("Result of Adding "+input1+" and "+input2+" is
:\t");
System.out.println(df.format(result)); //printing result upto 2
deciaml places
System.out.println("Press any key and press Enter");
char
temp=ai.next().charAt(0); //used for pressing enter
if (temp!='~')
{
calculate();
}
}
catch(Exception e)
{
System.out.println("You are Supposed to give input
Correctly\n\n");
//Messaging
users to to give correct input
calculate();
}
}
public static void sub()
{
Scanner ai=new
Scanner(System.in);//defining for taking inputs from console
DecimalFormat df = new
DecimalFormat();
df.setMaximumFractionDigits(2);
System.out.println("Enter two
values for Subtraction");
try{
input1=ai.nextFloat();
input2=ai.nextFloat();
float
result=input1-input2;
System.out.print("Result of Subtracting "+input1+" and"+input2+" is
:\t");
System.out.println(df.format(result));
System.out.println("Press any key and press Enter");
char
temp=ai.next().charAt(0);
if (temp!='~')
{
calculate();
}
}
catch(Exception e)
{
System.out.println("You are Supposed to give input
Correctly\n\n");
calculate();
}
}
public static void mul()
{
Scanner ai=new
Scanner(System.in);//defining for taking inputs from console
DecimalFormat df = new
DecimalFormat();
df.setMaximumFractionDigits(2);
System.out.println("Enter two
values for Multiplication");
try{
input1=ai.nextFloat();
input2=ai.nextFloat();
float
result=input1*input2;
System.out.print("Result of Multiplying "+input1+" and "+input2+"
is :\t");
System.out.println(df.format(result));
System.out.println("Press any key and press Enter");
char
temp=ai.next().charAt(0);
if (temp!='~')
{
calculate();
}
}
catch(Exception e)
{
System.out.println("You are Supposed to give input
Correctly\n\n");
calculate();
}
}
public static void div()
{
Scanner ai=new
Scanner(System.in);//defining for taking inputs from console
DecimalFormat df = new
DecimalFormat();
df.setMaximumFractionDigits(2);
System.out.println("Enter two
values for Division");
try{
input1=ai.nextFloat();
input2=ai.nextFloat();
int
temp1=(int)input2;
while(temp1==0)
{
System.out.println("You cannot divide by
zero.please re-enter");
//to re take inputs from the user when Entered
0
input2=ai.nextFloat();
temp1=(int)input2;
}
float
result=input1/input2;
System.out.print("Result of Dividing "+input1+" by "+input2+" is
:\t");
System.out.println(df.format(result));
System.out.println("Press any key and press Enter");
char
temp=ai.next().charAt(0);
if (temp!='~')
{
calculate();
}
}
catch(Exception e)
{
System.out.println("You are Supposed to give input
Correctly\n\n");
calculate();
}
}
public static int menu()
{
Scanner mi=new
Scanner(System.in);
//here mi as menu_input
System.out.println("Welcome to
Adi's Handy Calculator\n");
System.out.println("1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\n5.Exit");
System.out.print("What would you
like to do?\t");
int choice; //taking choice from
user
choice=mi.nextInt();
return choice; //return user choice
to calculate
}
}
Note: I took Entered key as an Any character input to exit.
A Simple Calculator Summary: Write a console program (character based) to do simple calculations (addition, subtraction,...
Write a Python Program that displays repeatedly a menu as shown in the sample run below. The user will enter 1, 2, 3, 4 or 5 for choosing addition, substation, multiplication, division or exit respectively. Then the user will be asked to enter the two numbers and the result for the operation selected will be displayed. After an operation is finished and output is displayed the menu is redisplayed, you may choose another operation or enter 5 to exit the...
Design a calculator program that will add, subtract, multiply, or divide two numbers input by a user.Your program should contain the following:-The main menu of your program is to continue to prompt the user for an arithmetic choice until the user enters a sentinel value to quit the calculatorprogram.-When the user chooses an arithmetic operation (i.e. addition) the operation is to continue to be performed (i.e. prompting the user for each number, displayingthe result, prompting the user to add two...
This is a quick little assignment I have to do, but I missed alot
of class due to the Hurricane and no one here knows what theyre
doing. please help! this is Java with intelli-J
Overview In this project students will build a four-function one-run calculator on the command line. The program will first prompt the user for two numbers, then display a menu with five operations. It will allow the user to select an option by reading input using...
Task 2.5: A simple calculator (25 marks) In this task you will develop a MARIE program that implements four basic functions of a calculator: addition, subtraction, multiplication, division, and exponent. The program should be performing the user selected tasks (one of the mentioned mathematical operations) after the user enters one of the selection inputs, ‘a’, ‘s’, ‘m’, ‘d’ or ‘p’. Here, input ‘a’ selects addition process, ‘s’ selects subtraction process, ‘m’ selects multiplication process, ‘d’ selects division process, and ‘p’...
(For Python program) Write a program that fulfills the functionalities of a mathematical quiz with the four basic arithmetic operations, i.e., addition, subtraction, multiplication and integer division. A sample partial output of the math quiz program is shown below. The user can select the type of math operations that he/she would like to proceed with. Once a choice (i.e., menu option index) is entered, the program generates a question and asks the user for an answer. A sample partial output...
Write a C++ Program that simulates a basic calculator using functions which performs the operations of Addition, Subtraction, multiplication, and Division. ( make sure you cover the case to avoid division by a zero) Display a menu for list of operations that can be calculated and get the input from user about his choice of calculation. Based on user choice of operation, take the input of number/numbers from user. Assume all input values are of type double. Calculations must be...
Write a C++ Program that simulates a basic calculator using functions which performs the operations of Addition, Subtraction, multiplication, and Division. ( make sure you cover the case to avoid division by a zero) Display a menu for the list of operations that can be calculated and get the input from the user about his choice of calculation. Based on user choice of operation, take the input of number/numbers from user. Assume all input values are of type double. Calculations...
Problem 3 (35) Design a calculator that performs four operations: addition, multiplication, division and subtraction with 2 integer type numbers a) Ask user what type of operation to perform (+, , * or/) a. If the user inputs 'none' then the program terminates. Otherwise it will keep continuing the calculation. (hint: use while) b) Ask user to provide 2 integer number inputs c) Perform operation (whatever operation they mentioned in a) d) Print result e) In division operation, perform a...
In this lab you will code a simple calculator. It need not be anything overly fancy, but it is up to you to take it as far as you want. You will be creating this program in three small sections. You have the menu, the performance of the basic arithmetic operations (Addition, Subtraction Multiplication, and Division), and the looping. You may want to get the switch menu working first, and then fill in the code for these four arithmetic operations...
Read description carefully. Needs to catch exceptions and still be
able to keep the program going on past the error. Program should
allow user to keep going until he or she quits
Math tutor) Write a program that displays a menu as shown in the sample run. You can enter 1, 2. 3, or 4 for choosing an addition. subtraction, multiplication, or division test. After a test is finished, the menu is redisplayed. You may choose another test or enter...