Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.ArrayList;
- import java.util.Scanner;
- //Main == CarDatabaseJava
- public class Main {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- ArrayList<Car> arr = new ArrayList<Car>();
- Scanner scan = new Scanner(System.in);
- char selection = 'a';
- while (selection != 'q')
- {
- System.out.println();
- System.out.println("\tCAR DATABASE ");
- System.out.println("\tType: ");
- System.out.println("\t\ta - to input a new entry from keyboard");
- System.out.println("\t\tb - to print all entries so far");
- System.out.println("\t\tq - to quit\n");
- System.out.print("\tEnter selection: ");
- selection = scan.next().charAt(0);
- switch (selection)
- {
- case 'a':
- Car theCar = new Car();
- inputDetails(theCar);
- outputInfo(theCar);
- arr.add(theCar);
- break;
- case 'b':
- System.out.println(arr.size());
- for (int i = 0; i < arr.size(); i++) {
- System.out.println("Car ID = " + i);
- printCarInfo(arr.get(i));
- }
- break;
- }
- }
- System.out.println("\tPROGRAM ENDED\n");
- }
- private static void inputDetails(Car aCar){
- Scanner scan = new Scanner(System.in);
- System.out.print("\n\tEnter the manufacturer of the car: ");
- aCar.setManufacturer(scan.nextLine());
- System.out.print("\tEnter the model of the car: ");
- aCar.setModel(scan.nextLine());
- System.out.print("\tEnter the registration number of the car: ");
- aCar.setRnumber(scan.nextInt());
- System.out.print("\tEnter the price of the car: ");
- aCar.setPrice(scan.nextFloat());
- System.out.print("\tEnter the colour of the car: ");
- String s = scan.nextLine();
- s = scan.nextLine(); ///idk why, but first scan.nextLine() return "" (empty string)
- aCar.setColour(s);
- System.out.print("\n\tThank you.");
- }
- private static void outputInfo(Car aCar){
- System.out.print("\n\tNew registered car:");
- }
- private static void printCarInfo(Car car) {
- System.out.println("Manufacturer: " + car.getManufacturer());
- System.out.println("Reg. number: " + car.getRnumber());
- System.out.println("Model: " + car.getModel());
- System.out.println("Price: " + car.getPrice());
- System.out.println("Color: " + car.getColour());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement