Question

In: Computer Science

Write a JAVA program in eclipse (write comment in every line) that asks the user to...

Write a JAVA program in eclipse (write comment in every line) that asks the user to enter two numbers and an operator (+, -, *, / or %), obtain them from the user and prints their sum, product, difference, quotient or remainder depending on the operator. You need to use OOP techniques (objects, classes, methods….). This program must be place in a loop that runs 3 times.

Solutions

Expert Solution

code:

import java.util.Scanner;
//importing package
public class Main
//initialising the class named Main
{
int add(int num1, int num2)
//method to perform addition
{
return num1+num2;
// returning the answer of addition
}
int sub(int num1, int num2)
//method to perform subtration
{
return num1-num2;
// returning the answer of subtraction
}
int mul(int num1, int num2)
//method to perform multiplication
{
return num1*num2;
// returning the answer of multiplication
}

int div(int num1, int num2)
//method to perform division
{
return num1/num2;
// returning the answer of division
}
int modu(int num1, int num2)
//method to perform Modulus(reminder)
{
return num1%num2;
// returning the answer of modulus
}
public static void main(String[] args)
//main method here the execution starts
{
Scanner in = new Scanner(System.in);
// Input two numbers from user
System.out.println("Enter first number :");
int num1 = in.nextInt();
//first input
System.out.println("Enter second number :");
int num2 = in.nextInt();
//second input
   Main obj = new Main();
   //creating object for Main class
System.out.println("Addition: "+obj.add(num1,num2));
//This will call the add method
System.out.println("Substaction: "+obj.sub(num1,num2));
//This will call the sub method//This will call the mul method
System.out.println("Multiplicat/ion: "+obj.mul(num1,num2));
//This will call the mul method
System.out.println("Division: "+obj.div(num1,num2));
//This will call the div method
System.out.println("Reminder(modulus): "+obj.modu(num1,num2));
//This will call the modu method
}
//end of main method
}
//end of class Main

Screenshots:

Thank you.


Related Solutions

Write in JAVA eclipse program (comment in every line): class for calculating an area of a...
Write in JAVA eclipse program (comment in every line): class for calculating an area of a room. The program MUST ask for the length and the width of the room. Make sure you write the methods to get the width and length and print the area.
Program: Java (using eclipse) Write a program that asks the user to enter today’s sales for...
Program: Java (using eclipse) Write a program that asks the user to enter today’s sales for five stores. The program should then display a bar chart comparing each store’s sales. Create each bar in the bar chart by displaying a row or asterisks. Each asterisk should represent $100 of sales. You must use a loop to print the bar chart!!!! If the user enters a negative value for the sales amount, the program will keep asking the user to enter...
This is Java In this problem we will write a program that asks the user to...
This is Java In this problem we will write a program that asks the user to enter a) The user's first name and b) a series of integers separated by commas. The integers may not include decimal points nor commas. The full string of numbers and commas will not include spaces either, just digits and commas. An example of valid input string is:        7,9,10,2,18,6 The string must be input by the user all at once; do not use a loop...
Write a program IN JAVA that asks the user for a number. The program should check...
Write a program IN JAVA that asks the user for a number. The program should check the number to ensure that it is valid (if not, the user should enter a valid number to continue.) The program should print out all of the prime numbers from 2 up to the number, with up to 10 numbers per line. (Recall: A prime number is a number that is only divisible by itself and 1.) The code should ask the user if...
Program should be written in Java a) Write a program that asks the user to enter...
Program should be written in Java a) Write a program that asks the user to enter the approximate current population of India. You should have the computer output a prompt and then YOU (as the user should enter the population.)  For testing purposes you may use the value of 1,382,000,000 from August 2020. Assume that the growth rate is 1.1% per year. Predict and print the predicted population for 2021 and 2022. The printout should include the year and the estimated...
Write a Java program that asks the user to enter an integer that is used to...
Write a Java program that asks the user to enter an integer that is used to set a limit that will generate the following four patterns of multiples of five using nested loops •Ascending multiples of five with ascending length triangle •Ascending multiples of five with descending length (inverted) triangle •Descending multiples of five with ascending length triangle •Descending multiples of five with descending length (inverted) triangle Use error checking to keep asking the user for a positive number until...
In java, write a program that asks the user to enter a character. Then pass the...
In java, write a program that asks the user to enter a character. Then pass the character to the following methods. isVowel() – returns true if the character is a vowel isConsonant() – returns true if the character is a consonant changeCase() – if the character is lower case then change it to upper case and if the character is in upper case then change it to lower case. (return type: char) Example output is given below: Enter a character...
IN JAVA write a program that asks a user for a maximum of 20 user-inputted elements...
IN JAVA write a program that asks a user for a maximum of 20 user-inputted elements and create an array. Then, write a Merge Sort function with recursion (in the main) that takes the user inputted elements in the array, sorts them, and prints them back.
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
Write a java program that asks the user for a number n and gives them the...
Write a java program that asks the user for a number n and gives them the possibility to choose between computing the sum and computing the product of 1,…,n. Example of running this program: Enter an integer number n: __7________ Enter Sum or Product: __Sum__________________________________ Program output: Sum of 1 ... 7 Sum or Product: Sum Sum = 28 Now second sample of second execution Enter an integer number n: __5__________________________________ Enter Sum or Product: __Product__________________________________ Program output:  Product of 1...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT