8 92 Wed Nov 99 42 46 PM a EE Chrome File Edit View History

8 92% Wed Nov 99 42 46 PM a EE Chrome File Edit View History Bookmarks People Window Help E Lab Assignments Mod 6-Ch6 Programming Principles l Section 16 Fall Semester 2016 CO kennesaw.view.usg.edu een/ 18397105 10367 the sum of digits in an integer number. Follow the instructions in the problem statement. Design the main method ot your program such that it allows the user to re-run the program with different inputs e., use a loop structure) Document your code and organize the outputs properly using escape characters Program 2 Design and implement a Java program (name it MinMaxAvg) that defines three methods as follows Method max (int x, int y, int z) determines and returns the maximum value of three integer values Method min (int X, int y, int z) determines and returns the minimum value of three integer values Method average (int x, inty, int z) determines and returns the average of three integer values Test the methods with different input value read from the user (in the main method) Design the main method of your program such that it allows the userto re-run the program with different inputs (i.e use a loop structure). Document your code, and organize and space the outputs properly. Use escape characters to organize the outputs. Sample output is You entered: 20 8 12 Max value 20 Min value Average value 13.33333 333333 Proaram 3 View as Text

Solution

MinMaxAvg.java

import java.util.Scanner;


public class MinMaxAvg {

   public static void main(String[] args) {
   Scanner scan = new Scanner(System.in);
   while(true){
   System.out.print(\"Enter 3 numbers: \");
   int a = scan.nextInt();
   int b = scan.nextInt();
   int c = scan.nextInt();
   System.out.println(\"You entered: \"+a+\" \"+b+\" \"+c);
   System.out.println(\"Max value: \"+max(a,b,c));
   System.out.println(\"Min value: \"+min(a,b,c));
   System.out.println(\"Average value: \"+average(a,b,c));
   System.out.print(\"Do you want to continue (y/n): \" );
   char ch = scan.next().charAt(0);
   if(ch == \'n\' || ch==\'N\'){
       break;
   }
  
   }
   }
   public static int max(int x, int y, int z){
       if(x > y && x>z){
           return x;
       }
       else{
           if(y>z){
               return y;
           }
           else{
               return z;
           }
       }
   }
   public static int min(int x, int y, int z){
       if(x < y && x<z){
           return x;
       }
       else{
           if(y<z){
               return y;
           }
           else{
               return z;
           }
       }
   }
   public static double average(int x, int y, int z){
       return (x+y+z)/(double)3;
   }


}

Output:

Enter 3 numbers: 20 8 12
You entered: 20 8 12
Max value: 20
Min value: 8
Average value: 13.333333333333334
Do you want to continue (y/n): y
Enter 3 numbers: 2 1 3
You entered: 2 1 3
Max value: 3
Min value: 1
Average value: 2.0
Do you want to continue (y/n): n

 8 92% Wed Nov 99 42 46 PM a EE Chrome File Edit View History Bookmarks People Window Help E Lab Assignments Mod 6-Ch6 Programming Principles l Section 16 Fall
 8 92% Wed Nov 99 42 46 PM a EE Chrome File Edit View History Bookmarks People Window Help E Lab Assignments Mod 6-Ch6 Programming Principles l Section 16 Fall

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site