Question

Create two java programs. The first will ask the user to enter three integers. Once the...

Create two java programs. The first will ask the user to enter three integers.

Once the three integers are entered, ask the user to enter one of three functions. The “average” if they want the average of the three numbers entered, enter “min” if they want the minimum and “max” if they want the maximum.

Display the answer.

Ask the user if they want to calculate another function for the three numbers. If so, loop and ask what function they want, otherwise terminate the program.

The calculation of the answer must be done by a method that is in the second program.

The second java program will have a constructor, three instance variables of type integer and three methods. The constructor will require three integers that will place them in their corresponding instance variables.

The methods will be called average, minimum and maximum. They will all require no arguments and will return an int.

The average method will use the three instance variables as input and calculate the average of all three and return the average as an integer.

The maximum method will use the three instance variables as input and calculate the maximum of all three and return the maximum as an integer.

The minimum method will use the three instance variables as input and calculate the minimum of all three and return the minimum as an integer.

0 0
Add a comment Improve this question Transcribed image text
Answer #1


*******PROGRAM 1********

import java.util.Scanner;

public class Program_1 {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

//Take three numbers as input
System.out.println("Enter the First Number");
int num1 = sc.nextInt();
System.out.println("Enter the Second Number");
int num2 = sc.nextInt();
System.out.println("Enter the Third Number");
int num3 = sc.nextInt();
Program_2 calculate = new Program_2(num1, num2, num3);
int z ;
do {

//Asking the user to enter one of three functions.
System.out.println("Enter one of the three functionality");
String function = sc.next();
switch (function) {
case "average":
int avg=calculate.average();
System.out.println("Average of the three number is :"+avg+" ");
break;
case "min":
int min=calculate.mininum();
System.out.println("Minimum of the three number is :"+min+"");
break;
case "max":
int max=calculate.maximum();
System.out.println("Maximum of the three number is :"+max+"");
break;
}
System.out.println("Do you want to continue ?");
String check = sc.next();
if (check.equals("yes")) {
z = 1;
} else {
z = 0;
}
} while (z != 0);

}

}

*******PROGRAM 2********

class Program_2 {

int num_1;
int num_2;
int num_3;

Program_2(int num1, int num2, int num3) {
this.num_1 = num1;
this.num_2 = num2;
this.num_3 = num3;
}

//function to find average

int average() {
int result = (num_1 + num_2 + num_3) / 3;
return result;
}

//function to find maximum
int maximum() {
int result = num_1;
if (num_2 > result) {
result = num_2;
}
if (num_3 > result) {
result = num_3;
}
return result;
}

//function to find minimum
int mininum() {
int result = num_1;
if (num_2 < result) {
result = num_2;
}
if (num_3 < result) {
result = num_3;
}
return result;
}
}

*****OUTPUT FOR THE GIVEN CODE*****

run: Enter the First Number 4. Enter the Second Number Enter the Third Number Enter one of the three functionality average Average of the three number is : 6 Do you want to continue ? yes Enter one of the three functionality min Minimum of the three number is :4 Do you want to continue ? yes Enter one of the three functionality max Maximum of the three number Do you want to continue ? no BUILD SUCCESSFUL (total time: 36 seconds)

Add a comment
Know the answer?
Add Answer to:
Create two java programs. The first will ask the user to enter three integers. Once the...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA Ask the user for integers. If the user did not enter an integer, ask again....

    JAVA Ask the user for integers. If the user did not enter an integer, ask again. (Type Safe Input) Keep a running total of the intergers entered (sum). Once the user enters 0, stop looping. Print the sum of all the numbers. Do not use try-catch. EXAMPLE OUTPUT: Enter an integer, 0 to stop> [fasdfsa] Invalid input. Enter an integer, 0 to stop> [231.342] Invalid input. Enter an integer, 0 to stop> [1] Enter an integer, 0 to stop> [2]...

  • Create the following programs in Java {Java1 difficulty} [Please create as simple as possible] a. Ask...

    Create the following programs in Java {Java1 difficulty} [Please create as simple as possible] a. Ask the user to enter their favorite number and favorite word. Pass both of these values to a method that will print the favorite word vertically the favorite number of times. b. Ask the user to enter 2 integers. Pass the integers to 2 different methods: one method to add the integers and print the sum (from the method); the second method to multiply the...

  • Write a Java program that: • Asks the user to enter the number of integers that...

    Write a Java program that: • Asks the user to enter the number of integers that he need to enter; • Asked him to enter integer by integer; • Print The number of Odd numbers entered and the number of Even numbers entered. Important notes: 1. You should have to copy and paste the Java as your answer for this question. DON’T take screen shot for your Java Code. It must be editable. 2. Take a screen shot for your...

  • JAVA Write a program which will receive three pieces of data from the user: two floating...

    JAVA Write a program which will receive three pieces of data from the user: two floating point numbers, and a single character +, -, *, or /. Perform input validation on the character. Your code then will send these three pieces of data to a method which will calculate and output the results based on the user's entries. For example, if the user entered: "12.1, 23.2, +" the output would be "12.1 + 23.2 = 35.3." STRONG HINT: in a...

  • C++ Write a program that prompts the user to enter integers or a sentinel to stop....

    C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...

  • In this assignment you will create two Java programs: The first program will be a class...

    In this assignment you will create two Java programs: The first program will be a class that holds information (variables) about an object of your choice and provides the relevant behavior (methods) The second program will be the main program which will instantiate several objects using the class above, and will test all the functions (methods) of the class above. You cannot use any of the home assignments as your submitted assignment. Your programs must meet the following qualitative and...

  • In Java Write a program that will ask the user for integers and print if the...

    In Java Write a program that will ask the user for integers and print if the integer is positive, negative or zero. The program should continue asking for integer until the user enters a negative value.

  • Write a Java program to meet the following requirements: 1. Prompt the user to enter three...

    Write a Java program to meet the following requirements: 1. Prompt the user to enter three strings by using nextLine(). Space can be part of the string). ( Note: your program requires using loop: for-loop, while-loop or do-while-loop to get the input String ) 2. Write a method with an input variable (string type).The method should return the number of lowercase letters of the input variable. 3. Get the number of the lowercase letters for each user input string by...

  • PLEASE INCLUDE COMMENTS In java Create a Java Program Add the following comments at the beginning...

    PLEASE INCLUDE COMMENTS In java Create a Java Program Add the following comments at the beginning of the file: Your name. The name of the class(es) used in the program. The core concept (found below) for this lesson. The date the program was written. Include a recursive method separate from the main method that will add together all of the even numbers between and including 1 and the value the user supplies. For instance, if the user enters 10 then...

  • In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are...

    In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are in the range 0 to 100 inclusive. The program will ask a user to re-enter an integer if the user inputs a number outside of that range. The inputted integers must then be stored in a single dimensional array of size 20. Please create 3 methods: 1. Write a method public static int countEven(int[] inputArray) The method counts how many even numbers are in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT