Question

2.20 TEST 2: the worst calculator ever Input Prompt the user for 2 integers. Enter an...

2.20 TEST 2: the worst calculator ever Input

Prompt the user for 2 integers. Enter an integer: 5 Enter another integer: 2 Processing Modify the first integer by adding 1 to it and save the new value into a variable called modified_int1. Modify the second integer by subtracting 1 from it and save the new value into a variable called modified_int2. Compute the sum, difference, product, quotient, and exponentiation of modified_int1 and modified_int2 and save each into a variable. Print a warning message informing the user that this calculator is not to be trusted. Print the original numbers, the operations, and the new results (as shown below).

Output

Enter an integer: 5

Enter another integer: 2

WARNING: These results are probably wrong!!!

5 + 2 = 7

5 - 2 = 5

5 * 2 = 6

5 / 2 = 6

5 ^ 2 = 6

Homework Answers

Answer #1

WorstCalculator.java

import java.util.Scanner;

public class WorstCalculator {
   public static void main(String[] args) {
       // Scanner class object to get the input from user
       Scanner input=new Scanner(System.in);
       System.out.print("Enter an integer: ");
       int integer1=input.nextInt(); // accept first integer
       System.out.print("Enter another integer: ");
       int integer2=input.nextInt(); // accept second integer
       // Modify the first integer by adding 1 to it
       // and save the new value into a variable called modified_int1
       int modified_int1=integer1+1;
       // Modify the second integer by subtracting 1 from it
       // and save the new value into a variable called modified_int2
       int modified_int2=integer2-1;
       System.out.println("\nWARNING: These results are probably wrong!!!");
       // calculate and print results
       System.out.println(integer1+" + "+integer2+" = "+(modified_int1+modified_int2));
       System.out.println(integer1+" - "+integer2+" = "+(modified_int1-modified_int2));
       System.out.println(integer1+" * "+integer2+" = "+(modified_int1*modified_int2));
       System.out.println(integer1+" / "+integer2+" = "+(modified_int1/modified_int2));
       System.out.println(integer1+" ^ "+integer2+" = "+((int)Math.pow(modified_int1, modified_int2)));
       input.close(); // close Scanner object
   }
}

Sample run 1

Sample run 2

Note--> If you want this solution in any other programming language then comment below....

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Create a simple addition calculator in Java. The program should prompt the user to enter 2...
Create a simple addition calculator in Java. The program should prompt the user to enter 2 integers, then adds the numbers and prints the result. Make sure the program includes appropriate exception handling in case the user does not enter appropriate integer values.
Assembler lanaguage program   The program is to prompt the user to enter a number between 2...
Assembler lanaguage program   The program is to prompt the user to enter a number between 2 and 100. Reject any invalid user inputs and terminate the program if invalid inputs are entered. Print each even number from 2 to the user entered number. Sum these even numbers and print the sum. Print each odd number from 1 to the user entered number. Sum these odd numbers and print the sum. Exit the program when the output is complete. The output...
1) Create an interface to the keyboard (Scanner). Scanner is described in Chapter 2. 2) Prompt...
1) Create an interface to the keyboard (Scanner). Scanner is described in Chapter 2. 2) Prompt the user to enter their first and last name.. 3) Read the name into a String. 4) Print a person greeting such as “Hello FirstName LastName”. Print the users name in the greeting. 5) Prompt the user to enter 2 integers. 6) Read the integers into 2 variables into your program. 7) Prompt the user to enter a math operation – one of +,-,*,/...
Write a Python program that prompts a user for two integers and stores the two integers...
Write a Python program that prompts a user for two integers and stores the two integers the user types into the shell. Print the product, float division, integer division, remainder, sum, and difference of the two integers to the console. The entire equation must be printed (see below for formatting). Only display 2 digits after the decimal place for results that are floats. Include a module docstring that summarizes the program.. Sample Run 1: Enter an integer: 5 Enter another...
x86 irvine library assembly code Write a complete program that: 1. Prompt the user to enter...
x86 irvine library assembly code Write a complete program that: 1. Prompt the user to enter 10 numbers. 2. save those numbers in a 32-bit integer array. 3. Print the array with the same order it was entered. 3. Calculate the sum of the numbers and display it. 4. Calculate the mean of the array and display it. 5. Rotate the members in the array forward one position for 9 times. so the last rotation will display the array in...
Program Behavior Each time your program is run, it will prompt the user to enter the...
Program Behavior Each time your program is run, it will prompt the user to enter the name of an input file to analyze. It will then read and analyze the contents of the input file, then print the results. Here is a sample run of the program. User input is shown in red. Let's analyze some text! Enter file name: sample.txt Number of lines: 21 Number of words: 184 Number of long words: 49 Number of sentences: 14 Number of...
4) Write a java program where you will use while loop, where if condition is equal...
4) Write a java program where you will use while loop, where if condition is equal to 2 (or any other choice of your number) then it will break the while condition. Steps: 1) Declare variable int (any name) which is equal to zero 2) Declare while condition which variable int is less then equal to 10 3) Declare print out where the value of variable is the same name that you declared in step 1 4) Declare condition if...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
In C programming, Thank you Write a program to compute the area of a circle. You...
In C programming, Thank you Write a program to compute the area of a circle. You have to write a complete “C” program that compiles and runs in Codeblocks. Program requirements: 1. Declare the variables needed: radius (r) and area (yourLastName). 2. Calculate and print the area of each circle. 3. The program MUST prompt the user for a new radius (r) over and over until the user types -1. 5. Use the type double for all decimal numbers. 6....
This program will store roster and rating information for a soccer team. Coaches rate players during...
This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balanced team. (1) Prompt the user to input five pairs of numbers: A player's jersey number (0 - 99) and the player's rating (1 - 9). Store the jersey numbers in one int vector and the ratings in another int vector. Output these vectors (i.e., output the roster). (3 pts) Ex: Enter player 1's jersey number: 84 Enter player 1's...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT