Question

In: Computer Science

In this project you will create a basic console based calculator program. The calculator can operate...

In this project you will create a basic console based calculator program.
The calculator can operate in two modes: Standard and Scientific modes. 
The Standard mode will allow the user to perform the following operations: 
(+, -, *, /) add, subtract, multiply, and divide
The Scientific mode will allow the user to perform the same functionality as the Standard 
add, subtract, multiply, and divide (+, -, *, / ) plus the following: 
sin x, cos x, tan x. (sin x, cos x, tan x)
The calculator should be able to perform addition, subtraction, multiplication, and division of two or more numbers but perform sin x, cos x, and tan x of one number only (the number is in radians). 

1. The calculator program will first ask the user for the mode to operate in (Standard or Scientific)

      Sample Output: 
      Enter the calculator mode: Standard/Scientific?
      Standard

2. The program should then ask the user for the operation to execute (+, -, *, /, sin x, cos x, tan x)

      Sample Output for Scientific mode:
      Enter '+' for addition, '-' for subtractions, '*' for multiplication, '/' for division, 'sin' for sin x, 'cos' for cos x, 'tan' for tan x:
      sin

      Sample Output for Scientific mode:
      Enter '+' for addition, '-' for subtractions, '*' for multiplication, '/' for division, 'sin' for sin x, 'cos' for cos x, 'tan' for tan x:
      sin

2a. If the user enters an invalid operation, output a message telling the user the input is invalid and re-prompt the user for the operation again.

      Enter '+' for addition, '-' for subtractions, '*' for multiplication, '/' for division, 'sin' for sin x, 'cos' for cos x, 'tan' for tan x:
      division 

      Invalid operation entered

      Enter '+' for addition, '-' for subtractions, '*' for multiplication, '/' for division, 'sin' for sin x, 'cos' for cos x, 'tan' for tan x:
      / 

3. In order to know how many times the user will need to perform the operation, prompt the user for the number of double values they want to enter (All numbers in this program are double), then ask the user to enter the numbers. 

      Sample Output:
      How many numbers do you want to subtract:
      3
      Enter 3 numbers:
      4
      35
      9

In this example the calculator will calculate 4 + 35 + 9. The result will be 48.

The calculator should be able to perform the following operations:

      2+3 = 5
      3+6+1+1+1 = 12
      1-2-90 = -91
      10*2*3 = 60
      10/2/5 = 1
      cos(0) = 1
      sin(0) = 0
      tan(0) = 0

Note: This calculator does NOT support multiple operations in the expressions like: 10+2-8
Note: Multiple numbers are only acceptable for the operations of (+, -, *, / ) not for (sin,cos,tan)

4. Display the result
      Sample Output:
      Result: 50.0

5. Finally, output the result to the user and ask the user if he/she want to start over. 
      Sample Output:
      Start over? Y/N
      Y

Full Sample Output:
Enter the calculator mode: Standard/Scientific?
Standard

Enter '+' for addition, '-' for subtractions, '*' for multiplication, '/' for division, 'sin' for sin x, 'cos' for cos x, 'tan' for tan x:
addition

Invalid operation entered

Enter '+' for addition, '-' for subtractions, '*' for multiplication, '/' for division, 'sin' for sin x, 'cos' for cos x, 'tan' for tan x:
+

How many numbers do you want to subtract:
3
Enter 3 numbers:
4
35
9
Result: 48.0
Start over? Y/N
Y
Enter the calculator mode: Standard/Scientific?
Scientific

Enter '+' for addition, '-' for subtractions, '*' for multiplication, '/' for division, 'sin' for sin x, 'cos' for cos x, 'tan' for tan x:
sin

Enter number in radians to find sin:
1.5708
Result: 1
Start over? Y/N
N

Solutions

Expert Solution

/******************************************************************************

Online Java Compiler.
Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/

public class Main
{
int modeCount;
public showStOperation(){
       System.out.println(" Enter '+' for addition, '-' for subtractions, '*' for multiplication, '/' for division");
  
}
public showScOperation(){
System.out.println("Enter '+' for addition, '-' for subtractions, '*' for multiplication, '/' for division, 'sin' for sin x, 'cos' for cos x, 'tan' for tan x:");
  
}
public void modeCount(int count){
this.modeCount=count;
}
public void addition(){
       Scanner myObj = new Scanner(System.in); // Create a Scanner object
int sum=0;
for(int i=0;i<count;i++){
sum=sum+myObj.nextInt();
}
        System.out.println("The sum is "+sum);

}
  
  
   public static void main(String[] args) {
   Main main=new Main();
       System.out.println("Enter the calculator mode: Standard/Scientific?");
       Scanner myObj = new Scanner(System.in); // Create a Scanner object
String mode = myObj.nextLine();
if(mode.equalIgnoreCase("standard")){
main.showStOperation();
}
else if(mode.equalIgnoreCase("scientific")){
main.showScOperation();
}
else{
        System.out.println("Invalid calculator");

}
   System.out.println("How many numbers do you want to perform");
int count = myObj.nextInt();
main.modeCount(count);
  
   }
}

Since the question has many part I am answering only 4


Related Solutions

You are going to create a console based program to keep track of a small business...
You are going to create a console based program to keep track of a small business that sells Doodads. First you will need to create a class Doodad that keeps track of two integers and two Strings. Next, create a constructor for the Doodad. Next, add getters and setters for each of the fields (two integers and two Strings). You need to use Doodad.java (see the starter code) Inside your main method ask the user to read in the two...
Create a Visual Studio console project (c++) containing a main() program that declares a const int...
Create a Visual Studio console project (c++) containing a main() program that declares a const int NUM_VALUES denoting the array size. Then declare an int array with NUM_VALUES entries. Using a for loop, prompt for the values that are stored in the array as follows: "Enter NUM_VALUES integers separated by blanks:" , where NUM_VALUES is replaced with the array size. Then use another for loop to print the array entries in reverse order separated by blanks on a single line...
Create a C# console application (do not create a .NET CORE project) and name the project....
Create a C# console application (do not create a .NET CORE project) and name the project. Generate two random integers, each between 1 and 50, that you will be adding together to test the user's ability to perform the addition operator. Display the numbers in the console, such as:             7 + 22 = ? Once the user provides their answer, check to see if it is correct and if not, tell them sorry, please try again. If their answer...
Create a C# console application (do not create a .NET CORE project) and name the project...
Create a C# console application (do not create a .NET CORE project) and name the project TuitionIncrease. The college charges a full-time student $12,000 in tuition per semester. It has been announced that there will be a tuition increase by 5% each year for the next 7 years. Your application should display the projected semester tuition amount for the next 7 years in the console window in the following format:             The tuition after year 1 will be $12,600. Note:...
Create a C# console application (do not create a .NET CORE project) and name the project...
Create a C# console application (do not create a .NET CORE project) and name the project TimeToBurn. Running on a particular treadmill, you burn 3.9 calories per minute. Ask the user how many calories they wish to burn in this workout session (this is their goal). Once they tell you, output on the console after each minute, how many calories they have burned (e.g. After 1 minute, you have burned 3.9 calories). Keep outputting the total amount of calories they...
Make a Program in Visual Studio / Console App (.NET Framework) # language Visual Basic You...
Make a Program in Visual Studio / Console App (.NET Framework) # language Visual Basic You will be simulating an ATM machine as much as possible Pretend you have an initial deposit of 1000.00. You will Prompt the user with a Main menu: Enter 1 to deposit Enter 2 to Withdraw Enter 3 to Print Balance Enter 4 to quit When the user enters 1 in the main menu, your program will prompt the user to enter the deposit amount....
C++ Project 6-2: Pig Latin Translator Create a program that translates English to Pig Latin. Console...
C++ Project 6-2: Pig Latin Translator Create a program that translates English to Pig Latin. Console Pig Latin Translator This program translates a sentence and removes all punctuation from it. Enter a sentence: 'Tis but a scratch. Translation:      Istay utbay away atchscray Specifications Convert the English to lowercase before translating. Remove all punctuation characters before translating. Assume that words are separated from each other by a single space. If the word starts with a vowel, just add way to the...
Java For this project, we want to build a calculator program that can perform simple calculations...
Java For this project, we want to build a calculator program that can perform simple calculations and provide an output. If it encounters any errors, it should print a helpful error message giving the nature of the error. You may use any combination of If-Then statements and Try-Catch statements to detect and handle errors. Program Specification Input Our program should accept input in one of two ways: If a command-line argument is provided, it should read input from the file...
1. Create a console program in C#, * Create a class: "Student.cs" * Add 3 variables:...
1. Create a console program in C#, * Create a class: "Student.cs" * Add 3 variables: StudentName (string), SchoolYear (int), YearsUntilGraduation(int) * Method YTK() = 12 - SchoolYear; 2. Main *Enter name *Enter age *You will attend school:____ years before graduating.
write a small visual basic console program to output the ages of three students
write a small visual basic console program to output the ages of three students
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT