Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How to make this program output sent it to the file. import java.util.Scanner; public class llll6 { static Scanner input = new Scanner(System.in); //input object

How to make this program output sent it to the file.

import java.util.Scanner;

public class llll6 {

static Scanner input = new Scanner(System.in); //input object of scanner class for take single input from the user

static int a,b,result; //variable a and b for take input from the user and result is for storing the result

static char ch; //ch for take an input from the user

public static void main(String[] args) {

boolean done = false; //done is for continue the while loop

while (done == false) {

System.out.print("SIMPLE CALCULTOR ");

System.out.println("Select an option for calculation operation");

System.out.print("+ Addition, - Subtraction, * Multiplication, / division, % Modulation, A. Average, X. Maximum, M. Minimum, S. Square, Q. Quit ");

System.out.print("Enter Option: ");

ch = input.next().charAt(0); // a single character input from the user and store in ch variable

//switch case for inputed operation

switch (ch) {

case '+':

input(); // take input from the user

add(); //add method called when user enter +

prints(); // prints the result

break;

case '-':

input(); // take input from the user

subtract(); //subtract method called when user enter -

prints(); // prints the result

break;

case '*':

input(); // take input from the user

multiply(); //mutiply method called when user enter *

prints(); // prints the result

break;

case '/':

input(); // take input from the user

divide(); //divide method called when user enter /

prints(); // prints the result

break;

case '%':

input(); // take input from the user

module(); //module method called when user enter %

prints(); // prints the result

break;

case 'A':

input(); // take input from the user

average(); //average method called when user enter A

prints(); // prints the result

break;

case 'X':

input(); // take input from the user

maximum(); //maximum method called when user enter X

prints(); // prints the result

break;

case 'M':

input(); // take input from the user

minimum(); //minimum method called when user enter M

prints(); // prints the result

break;

case 'S':

inputSquare();// take input from the user only one input

square(); //square method called when user enter S

prints(); // prints the result

break;

case 'Q':

System.exit(0); //quit the operation

}

}

}

public static void prints() {

if(ch=='+'){

System.out.println("Sample output:");

System.out.println("Operation:addition");

System.out.println("augend: "+a);

System.out.println("addend: "+b);

System.out.println("Sum: "+result);

}

if(ch=='-'){

System.out.println("Sample output:");

System.out.println("Operation: subtraction");

System.out.println("augend: "+a);

System.out.println("addend: "+b);

System.out.println("Subtraction: "+result);

}

if(ch=='*'){

System.out.println("Sample output:");

System.out.println("Operation: multiplication");

System.out.println("augend: "+a);

System.out.println("addend: "+b);

System.out.println("Multiplication: "+result);

}

if(ch=='/'){

System.out.println("Sample output:");

System.out.println("Operation: division");

System.out.println("augend: "+a);

System.out.println("addend: "+b);

System.out.println("Division: "+result);

}

if(ch=='%'){

System.out.println("Sample output:");

System.out.println("Operation: modulation");

System.out.println("augend: "+a);

System.out.println("addend: "+b);

System.out.println("Modulation: "+result);

}

if(ch=='A'){

System.out.println("Sample output:");

System.out.println("Operation:Average");

System.out.println("augend: "+a);

System.out.println("addend: "+b);;

System.out.println("Average: "+result);

}

if(ch=='X'){

System.out.println("Sample output:");

System.out.println("Operation: Maximum");

System.out.println("augend: "+a);

System.out.println("addend: "+b);

System.out.println("Maximum: "+result);

}

if(ch=='M'){

System.out.println("Sample output:");

System.out.println("Operation: Minimum");

System.out.println("augend: "+a);

System.out.println("addend: "+b);

System.out.println("Minimum: "+result);

}

if(ch=='S'){

System.out.println("Sample output:");

System.out.println("Operation: square");

System.out.println("first number: "+a);

System.out.println("Square: "+result);

}

// TODO Auto-generated method stub

}

public static void input() {

// TODO Auto-generated method stub

System.out.println("Please enter First number: ");

a = input.nextInt();

System.out.println("Please enter Second Number: ");

b = input.nextInt();

}

public static void inputSquare() {

System.out.println("Please enter number to get square of number: ");

a = input.nextInt();

}

public static void square() {

result = a*a;

}

public static void minimum() {

if(a

result = a;

else

result = b;

}

public static void maximum() {

if(a>b)

result = a;

else

result = b;

}

public static void average() {

result=(a+b)/2;

}

public static void module() {

result=a%b;

}

public static void divide() {

result=a/b;

}

public static void multiply() {

result=a*b;

}

public static void subtract() {

result=a-b;

}

public static void add() {

result=a+b;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mastering Influxdb Database A Comprehensive Guide To Learn Influxdb Database

Authors: Cybellium Ltd ,Kris Hermans

1st Edition

B0CNGGWL7B, 979-8867766450

More Books

Students also viewed these Databases questions

Question

6. Write a job specification.

Answered: 1 week ago

Question

Decision Making in Groups Leadership in Meetings

Answered: 1 week ago