Answer to Question #167508 in Java | JSP | JSF for ritheesh

Question #167508

2. Create another class Report holding a main function. This class will ask the user for type of data to be displayed like 1. Medical report 2. Grocery purchase bill 3. Electricity bill 4. Exit Once the choice is selected, write the code for invoking appropriate methods of the respective class for reading the details of three household and display the information.


1
Expert's answer
2021-02-28T07:03:40-0500
import java.util.Scanner;

public class Report {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String choice=in.nextLine();
        System.out.println("What type of data to display:");
        System.out.println("1. Medical report");
        System.out.println("2. Grocery purchase bill");
        System.out.println("3. Electricity bill");
        System.out.println("4. Exit");
        switch(choice){
            case "1":
                Diagnosis diagnosis = new Diagnosis();
                diagnosis.readData(in);
                System.out.println(diagnosis);
                break;
            case "2":
                Grocery  grocery  = new Grocery ();
                grocery.readData(in);
                grocery.computeData();
                break;
            case "3":
                Electricity  electricity  = new Electricity ();
                electricity.readData(in);
                electricity.computeData();
                break;
            case "4":
                System.exit(0);
                break;
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog