import java.io.*; //to use InputStreamReader and BufferedReader
import java.util.*; //to use ArrayList
import java.text.NumberFormat;
char input1;
String inputInfo = new String();
String line = new String();
boolean operation;
// ArrayList object is used to store vehicle objects
ArrayList<Vehicle> vehicleList = new ArrayList<Vehicle>();
try {
printMenu(); // print out menu
// create a BufferedReader object to read input from a
keyboard
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader stdin = new BufferedReader(isr);
do {
System.out.println("What action would you like to
perform?");
line = stdin.readLine().trim();
input1 = line.charAt(0);
input1 = Character.toUpperCase(input1);
if (line.length() == 1) {
switch (input1) {
case 'A': // Add Vehicle
System.out
.print("Please enter some vehicle
information to add:\n");
inputInfo = stdin.readLine().trim();
/*******************************************
****************************************
*** ADD your code here to create an object
of one of
* child classes of Vehicle class and add it
to the
* vehicleList
********************************************************************************
***/
Vehicle vehicle = VehicleParser
.parseStringToVehicle(inputInfo);
vehicleList.add(vehicle);
break;
case 'C': // Compute License Fee
/*******************************************
****************************************
*** ADD your code here to compute the
license fee for all
* vehicles the vehicleList.
********************************************************************************
***/
for (int i = 0; i < vehicleList.size(); i++)
{
public class Assignment 5 {
public static void main(String[] args) {
vehicleList.get(i).computeLicenseFee();
}
System.out.print("license fee computed\n");
break;
case 'D': // Count certain vehicles
System.out.print("Please enter a year to
compare:\n");
inputInfo = stdin.readLine().trim();
int year = Integer.parseInt(inputInfo);
int count = 0;
/*******************************************
****************************************
*** ADD your code here to count the number
of vehicles
* that are newer than the input year
********************************************************************************
***/
for (int i = 0; i < vehicleList.size(); i++)
{
if (vehicleList.get(i).getModelYear()
>= year) {
count++;
}
}
System.out
.println("The number of vehicles
that are newer than "
+ year + " is: " +
count);
break;
case 'L': // List Vehicles
/*******************************************
****************************************
*** ADD your code here to print out all
vehicle objects.
* If there is no vehicle, print "no
vehicle\n"
********************************************************************************
***/
if (vehicleList.size() == 0) {
System.out.print("no vehicle\n");
}
for (int i = 0; i < vehicleList.size(); i++)
{
System.out.print(vehicleList.get(i).toString());
}
break;
case 'Q': // Quit
break;
case '?': // Display Menu
printMenu();
break;
default:
System.out.print("Unknown action\n");
break;
}
} else {
System.out.print("Unknown action\n");
}
} while (input1 != 'Q'); // stop the loop when Q is read
} catch (IOException exception) {
System.out.println("IO Exception");
}
}
/** The method printMenu displays the menu to a user **/
public static void printMenu() {
System.out.print("Choice\t\tAction\n" + "------\t\t------\n"
+ "A\t\tAdd Vehicle\n" + "C\t\tCompute License Fee\n"
+ "D\t\tCount Certain Vehicles\n" + "L\t\tList
Vehicles\n"
+ "Q\t\tQuit\n" + "?\t\tDisplay Help\n\n");
}
}
Powered by TCPDF (www.tcpdf.org)