earlution

BasicAggregationWithMenu.java

Oct 5th, 2021 (edited)
743
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4.  * Basic aggregation class structure using a menu-based approach.
  5.  *
  6.  * @author (Ruari Mears)
  7.  * @version (05.01.2021)
  8.  */
  9. public class BasicAggregationWithMenu
  10. {
  11.     private AggregatedClass aggregatedObject = new AggregatedClass();
  12.  
  13.     public static void main(String[] args){
  14.         BasicAggregationWithMenu main = new BasicAggregationWithMenu();
  15.         main.menu();
  16.     }
  17.  
  18.     private void menu(){
  19.         Scanner scanner = new Scanner(System.in);
  20.         System.out.println("1 Standard output");
  21.         System.out.println("2 Standard input");
  22.         System.out.println("3 Standard input and output");
  23.         System.out.println("4 Menu item 4");
  24.         System.out.println();
  25.         System.out.println("Please enter your choice:");
  26.  
  27.         int choice = scanner.nextInt();
  28.  
  29.         switch (choice) {
  30.             case 1:
  31.                 System.out.println("You chose to see standard output...");
  32.                 aggregatedObject.standardOutput();
  33.                 break;
  34.             case 2:
  35.                 System.out.println("You chose to provide input to the " +
  36.                     "standard input stream...");
  37.                 aggregatedObject.standardInputAndOutput();
  38.                 break;
  39.             case 3:
  40.                 System.out.println("You chose the 3rd menu item...");
  41.                 aggregatedObject.method3();
  42.                 break;
  43.             case 4:
  44.                 System.out.println("You chose the 4th menu item...");
  45.                 aggregatedObject.method4();
  46.                 break;
  47.             default: System.out.println("Invalid choice");
  48.         }
  49.     }
  50. }
  51.  
Add Comment
Please, Sign In to add comment