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.
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;
}
}
}
Comments
Leave a comment