Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.78 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Scanner;
  5.  
  6.  
  7. //Main == CarDatabaseJava
  8. public class Main {
  9.  
  10.  
  11.     /**
  12.      * @param args the command line arguments
  13.      */
  14.     public static void main(String[] args) {
  15.         ArrayList<Car> arr = new ArrayList<Car>();
  16.         Scanner scan = new Scanner(System.in);
  17.  
  18.         char selection = 'a';
  19.         while (selection != 'q')
  20.         {
  21.             System.out.println();
  22.             System.out.println("\tCAR DATABASE ");
  23.             System.out.println("\tType: ");
  24.             System.out.println("\t\ta - to input a new entry from keyboard");
  25.             System.out.println("\t\tb - to print all entries so far");
  26.             System.out.println("\t\tq - to quit\n");
  27.             System.out.print("\tEnter selection: ");
  28.             selection = scan.next().charAt(0);
  29.             switch (selection)
  30.             {
  31.                 case 'a':
  32.                     Car theCar = new Car();
  33.                     inputDetails(theCar);
  34.                     outputInfo(theCar);
  35.                     arr.add(theCar);
  36.                     break;
  37.                 case 'b':
  38.                     System.out.println(arr.size());
  39.                     for (int i = 0; i < arr.size(); i++) {
  40.                         System.out.println("Car ID = " + i);
  41.                         printCarInfo(arr.get(i));
  42.                     }
  43.                     break;
  44.             }
  45.         }
  46.         System.out.println("\tPROGRAM ENDED\n");
  47.  
  48.  
  49.     }
  50.  
  51.     private static void inputDetails(Car aCar){
  52.         Scanner scan = new Scanner(System.in);
  53.  
  54.         System.out.print("\n\tEnter the manufacturer of the car: ");
  55.         aCar.setManufacturer(scan.nextLine());
  56.  
  57.         System.out.print("\tEnter the model of the car: ");
  58.         aCar.setModel(scan.nextLine());
  59.  
  60.         System.out.print("\tEnter the registration number of the car: ");
  61.         aCar.setRnumber(scan.nextInt());
  62.  
  63.         System.out.print("\tEnter the price of the car: ");
  64.         aCar.setPrice(scan.nextFloat());
  65.  
  66.         System.out.print("\tEnter the colour of the car: ");
  67.         String s = scan.nextLine();
  68.         s = scan.nextLine(); ///idk why, but first scan.nextLine() return "" (empty string)
  69.         aCar.setColour(s);
  70.  
  71.         System.out.print("\n\tThank you.");
  72.  
  73.  
  74.     }
  75.  
  76.     private static void outputInfo(Car aCar){
  77.  
  78.         System.out.print("\n\tNew registered car:");
  79.  
  80.  
  81.     }
  82.  
  83.     private static void printCarInfo(Car car) {
  84.         System.out.println("Manufacturer: " + car.getManufacturer());
  85.         System.out.println("Reg. number: " + car.getRnumber());
  86.         System.out.println("Model: " + car.getModel());
  87.         System.out.println("Price: " + car.getPrice());
  88.         System.out.println("Color: " + car.getColour());
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement