/* * @topic T00905 Car Inventory Sample * @brief Main driver * Class CarMain is written to test methods of the Car class. In addition, * static displayCar method gets an object of the car class * and it displays the info of the Car class. */ import java.util.Scanner; import java.text.NumberFormat; public class CarMain { //******************************************************************* public static void main(String args[]) { Scanner scnr = new Scanner(System.in); System.out.println("Welcome to the Car Inventory System "); System.out.println(); System.out.print("Enter the make of the car : "); String make = scnr.nextLine(); System.out.print("Enter the year of the car : "); int year = scnr.nextInt(); scnr.nextLine(); System.out.print("Enter the type of the car : "); String type = scnr.nextLine(); System.out.print("Enter the cost of the car : "); double cost = scnr.nextDouble(); Car c1 = new Car(make, year, type, cost); displayCar(c1); c1.setMake("Ford"); c1.setYear(1998); c1.setType("Truck Ranger"); c1.setCost(6575.45); displayCar(c1); } // end of main //****************************************************************** private static void displayCar(Car kar) { System.out.println(); System.out.println("Contents of the Car Object"); System.out.println("Make = " + kar.getMake()); System.out.println("Year = " + kar.getYear()); System.out.println("Type = " + kar.getType()); NumberFormat curr = NumberFormat.getCurrencyInstance(); System.out.println("Cost = " + curr.format(kar.getCost())); } // end of displayCar //****************************************************************** } // end of class CarMain /* Welcome to the Car Inventory System Enter the make of the car : Dodge Enter the year of the car : 2005 Enter the type of the car : passenger van Enter the cost of the car : 21795 Contents of the Car Object Make = Dodge Year = 2005 Type = passenger van Cost = $21,795.00 Contents of the Car Object Make = Ford Year = 1998 Type = Truck Ranger Cost = $6,575.45 */