SlideShare a Scribd company logo
1 of 15
Download to read offline
publicclass VehicleParser {
publicstatic Vehicle parseStringToVehicle(String lineToParse) {
String[] vehicleInfo = lineToParse.split("/");
if(vehicleInfo[0].equalsIgnoreCase("NewVehicle")) {
//type/make/modelYear/motivePower/vehiclePrice
returnnew NewVehicle(vehicleInfo[1],
Integer.parseInt(vehicleInfo[2]),
vehicleInfo[3],
Double.parseDouble(vehicleInfo[4]));
} elseif(vehicleInfo[0].equalsIgnoreCase("UsedVehicle")) {
//type/make/modelYear/motivePower/previousState/currentYear
returnnew UsedVehicle(vehicleInfo[1],
Integer.parseInt(vehicleInfo[2]),
vehicleInfo[3],
vehicleInfo[4],
Integer.parseInt(vehicleInfo[5]));
}
returnnull;
}
}
publicabstractclass Vehicle {
//Attributes
protected String make;
protectedint modelYear;
protected String motivePower;
protecteddouble licenseFee;
/**
* Constructor
* @param make
* @param modelYear
* @param motivePower
*/
public Vehicle(String make, int modelYear, String motivePower) {
this.make = make;
this.modelYear = modelYear;
this.motivePower = motivePower;
this.licenseFee = 0.0;
}
/**
* @return the modelYear
*/
publicint getModelYear() {
return modelYear;
}
@Override
public String toString() {
return " Make:tt" + this.make +
" Model Year:t" + this.modelYear +
" Motive Power:t" + this.motivePower +
" License Fee:t$" + this.licenseFee + " ";
}
publicabstractvoid computeLicenseFee();
}
publicclass NewVehicle extends Vehicle {
privatestaticdoubleBASE_FEE = 150.00;
privatestaticdoublePRICE_FEE = 0.15;
//Attributes
privatedouble vehiclePrice;
/**
* Constructor
* @param make
* @param modelYear
* @param motivePower
* @param vehiclePrice
*/
public NewVehicle(String make, int modelYear, String motivePower, double vehiclePrice) {
super(make, modelYear, motivePower);
this.vehiclePrice = vehiclePrice;
}
@Override
publicvoid computeLicenseFee() {
double smogAbatement = 0.0;
if(motivePower.equalsIgnoreCase("gas"))
smogAbatement = 20.00;
licenseFee = BASE_FEE + smogAbatement + (this.vehiclePrice * PRICE_FEE);
}
@Override
public String toString() {
return " NEW Vehicle:" +
super.toString() +
"Price:tt$" + this.vehiclePrice + "  ";
}
}
publicclass UsedVehicle extends Vehicle {
privatestaticdoubleBASE_FEE = 100.00;
privatestaticdoubleTITLE_TRANSFER_FEE = 15.00;
//Attributes
private String previousLicenseState;
privateint currentYear;
public UsedVehicle(String make, int modelYear, String motivePower, String
previousLicenseState, int currentYear) {
super(make, modelYear, motivePower);
this.previousLicenseState = previousLicenseState;
this.currentYear = currentYear;
}
@Override
publicvoid computeLicenseFee() {
double smogWaiverFee = 0.0;
if((this.currentYear - this.modelYear) >= 5)
smogWaiverFee = 8.00;
double smogAbatement = 0.0;
if(motivePower.equalsIgnoreCase("gas"))
smogAbatement = 20.00;
licenseFee = BASE_FEE + smogAbatement + TITLE_TRANSFER_FEE + smogWaiverFee;
}
@Override
public String toString() {
return " USED Vehicle:" +
super.toString() +
"Years Old:t" + (this.currentYear - this.modelYear) +
" Previous State:t" + this.previousLicenseState + "  ";
}
}
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
publicclass Assignment5 {
static Scanner scanner = new Scanner(System.in);
/**
* Clear keyboard buffer
*/
publicstaticvoid clearBuf(){
scanner.nextLine();
}
/**
* Prints the menu
*/
publicstaticvoid displayMenu(){
System.out.println("ChoicettAction ");
System.out.println("------tt------ ");
System.out.println("AttAdd Vehicle ");
System.out.println("CttCompute License Fee ");
System.out.println("DttCount Certain Vehicles ");
System.out.println("LttList Vehicles ");
System.out.println("QttQuit ");
System.out.println("?ttDisplay Help  ");
System.out.println("What action would you like to perform? ");
}
publicstaticvoid main(String args[]) {
List vehicleList= new ArrayList();
char choice = ' ';
while(true) {
displayMenu();
choice = Character.toUpperCase(scanner.next().charAt(0));
clearBuf();
switch (choice) {
case 'A': //Add Vehicle
System.out.println("Please enter some vehicle information to add: ");
Vehicle vehicle = VehicleParser.parseStringToVehicle(scanner.nextLine());
if(vehicle != null)
vehicleList.add(vehicle);
break;
case 'C': //Compute License Fee
for (Vehicle veh : vehicleList) {
veh.computeLicenseFee();
}
System.out.println("License fee computed ");
break;
case 'D': //Count Certain Vehicles
System.out.println("Please enter a year to compare: ");
int year = scanner.nextInt();
clearBuf();
int vehCount = 0;
for (Vehicle veh : vehicleList) {
if(veh.modelYear > year)
vehCount += 1;
}
System.out.println("The number of vehicles that are newer than " + year + " is: " + vehCount
+ " ");
break;
case 'L': //List Vehicles
if(vehicleList.size() > 0) {
for (Vehicle veh : vehicleList) {
System.out.println(veh);
}
} else
System.out.println("No vehicle ");
break;
case 'Q': //Quit
System.exit(0);
break;
case '?': //Display Help
break;
default:
System.out.println("Unknown action ");
}
}
}
}
SAMPLE OUTPUT:
Choice Action
------ ------
A Add Vehicle
C Compute License Fee
D Count Certain Vehicles
L List Vehicles
Q Quit
? Display Help
What action would you like to perform?
e
Unknown action
Choice Action
------ ------
A Add Vehicle
C Compute License Fee
D Count Certain Vehicles
L List Vehicles
Q Quit
? Display Help
What action would you like to perform?
l
No vehicle
Choice Action
------ ------
A Add Vehicle
C Compute License Fee
D Count Certain Vehicles
L List Vehicles
Q Quit
? Display Help
What action would you like to perform?
a
Please enter some vehicle information to add:
NewVehicle/GM/2016/gas/25000.50
Choice Action
------ ------
A Add Vehicle
C Compute License Fee
D Count Certain Vehicles
L List Vehicles
Q Quit
? Display Help
What action would you like to perform?
c
License fee computed
Choice Action
------ ------
A Add Vehicle
C Compute License Fee
D Count Certain Vehicles
L List Vehicles
Q Quit
? Display Help
What action would you like to perform?
l
NEW Vehicle:
Make: GM
Model Year: 2016
Motive Power: gas
License Fee: $3920.075
Price: $25000.5
Choice Action
------ ------
A Add Vehicle
C Compute License Fee
D Count Certain Vehicles
L List Vehicles
Q Quit
? Display Help
What action would you like to perform?
q
Solution
publicclass VehicleParser {
publicstatic Vehicle parseStringToVehicle(String lineToParse) {
String[] vehicleInfo = lineToParse.split("/");
if(vehicleInfo[0].equalsIgnoreCase("NewVehicle")) {
//type/make/modelYear/motivePower/vehiclePrice
returnnew NewVehicle(vehicleInfo[1],
Integer.parseInt(vehicleInfo[2]),
vehicleInfo[3],
Double.parseDouble(vehicleInfo[4]));
} elseif(vehicleInfo[0].equalsIgnoreCase("UsedVehicle")) {
//type/make/modelYear/motivePower/previousState/currentYear
returnnew UsedVehicle(vehicleInfo[1],
Integer.parseInt(vehicleInfo[2]),
vehicleInfo[3],
vehicleInfo[4],
Integer.parseInt(vehicleInfo[5]));
}
returnnull;
}
}
publicabstractclass Vehicle {
//Attributes
protected String make;
protectedint modelYear;
protected String motivePower;
protecteddouble licenseFee;
/**
* Constructor
* @param make
* @param modelYear
* @param motivePower
*/
public Vehicle(String make, int modelYear, String motivePower) {
this.make = make;
this.modelYear = modelYear;
this.motivePower = motivePower;
this.licenseFee = 0.0;
}
/**
* @return the modelYear
*/
publicint getModelYear() {
return modelYear;
}
@Override
public String toString() {
return " Make:tt" + this.make +
" Model Year:t" + this.modelYear +
" Motive Power:t" + this.motivePower +
" License Fee:t$" + this.licenseFee + " ";
}
publicabstractvoid computeLicenseFee();
}
publicclass NewVehicle extends Vehicle {
privatestaticdoubleBASE_FEE = 150.00;
privatestaticdoublePRICE_FEE = 0.15;
//Attributes
privatedouble vehiclePrice;
/**
* Constructor
* @param make
* @param modelYear
* @param motivePower
* @param vehiclePrice
*/
public NewVehicle(String make, int modelYear, String motivePower, double vehiclePrice) {
super(make, modelYear, motivePower);
this.vehiclePrice = vehiclePrice;
}
@Override
publicvoid computeLicenseFee() {
double smogAbatement = 0.0;
if(motivePower.equalsIgnoreCase("gas"))
smogAbatement = 20.00;
licenseFee = BASE_FEE + smogAbatement + (this.vehiclePrice * PRICE_FEE);
}
@Override
public String toString() {
return " NEW Vehicle:" +
super.toString() +
"Price:tt$" + this.vehiclePrice + "  ";
}
}
publicclass UsedVehicle extends Vehicle {
privatestaticdoubleBASE_FEE = 100.00;
privatestaticdoubleTITLE_TRANSFER_FEE = 15.00;
//Attributes
private String previousLicenseState;
privateint currentYear;
public UsedVehicle(String make, int modelYear, String motivePower, String
previousLicenseState, int currentYear) {
super(make, modelYear, motivePower);
this.previousLicenseState = previousLicenseState;
this.currentYear = currentYear;
}
@Override
publicvoid computeLicenseFee() {
double smogWaiverFee = 0.0;
if((this.currentYear - this.modelYear) >= 5)
smogWaiverFee = 8.00;
double smogAbatement = 0.0;
if(motivePower.equalsIgnoreCase("gas"))
smogAbatement = 20.00;
licenseFee = BASE_FEE + smogAbatement + TITLE_TRANSFER_FEE + smogWaiverFee;
}
@Override
public String toString() {
return " USED Vehicle:" +
super.toString() +
"Years Old:t" + (this.currentYear - this.modelYear) +
" Previous State:t" + this.previousLicenseState + "  ";
}
}
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
publicclass Assignment5 {
static Scanner scanner = new Scanner(System.in);
/**
* Clear keyboard buffer
*/
publicstaticvoid clearBuf(){
scanner.nextLine();
}
/**
* Prints the menu
*/
publicstaticvoid displayMenu(){
System.out.println("ChoicettAction ");
System.out.println("------tt------ ");
System.out.println("AttAdd Vehicle ");
System.out.println("CttCompute License Fee ");
System.out.println("DttCount Certain Vehicles ");
System.out.println("LttList Vehicles ");
System.out.println("QttQuit ");
System.out.println("?ttDisplay Help  ");
System.out.println("What action would you like to perform? ");
}
publicstaticvoid main(String args[]) {
List vehicleList= new ArrayList();
char choice = ' ';
while(true) {
displayMenu();
choice = Character.toUpperCase(scanner.next().charAt(0));
clearBuf();
switch (choice) {
case 'A': //Add Vehicle
System.out.println("Please enter some vehicle information to add: ");
Vehicle vehicle = VehicleParser.parseStringToVehicle(scanner.nextLine());
if(vehicle != null)
vehicleList.add(vehicle);
break;
case 'C': //Compute License Fee
for (Vehicle veh : vehicleList) {
veh.computeLicenseFee();
}
System.out.println("License fee computed ");
break;
case 'D': //Count Certain Vehicles
System.out.println("Please enter a year to compare: ");
int year = scanner.nextInt();
clearBuf();
int vehCount = 0;
for (Vehicle veh : vehicleList) {
if(veh.modelYear > year)
vehCount += 1;
}
System.out.println("The number of vehicles that are newer than " + year + " is: " + vehCount
+ " ");
break;
case 'L': //List Vehicles
if(vehicleList.size() > 0) {
for (Vehicle veh : vehicleList) {
System.out.println(veh);
}
} else
System.out.println("No vehicle ");
break;
case 'Q': //Quit
System.exit(0);
break;
case '?': //Display Help
break;
default:
System.out.println("Unknown action ");
}
}
}
}
SAMPLE OUTPUT:
Choice Action
------ ------
A Add Vehicle
C Compute License Fee
D Count Certain Vehicles
L List Vehicles
Q Quit
? Display Help
What action would you like to perform?
e
Unknown action
Choice Action
------ ------
A Add Vehicle
C Compute License Fee
D Count Certain Vehicles
L List Vehicles
Q Quit
? Display Help
What action would you like to perform?
l
No vehicle
Choice Action
------ ------
A Add Vehicle
C Compute License Fee
D Count Certain Vehicles
L List Vehicles
Q Quit
? Display Help
What action would you like to perform?
a
Please enter some vehicle information to add:
NewVehicle/GM/2016/gas/25000.50
Choice Action
------ ------
A Add Vehicle
C Compute License Fee
D Count Certain Vehicles
L List Vehicles
Q Quit
? Display Help
What action would you like to perform?
c
License fee computed
Choice Action
------ ------
A Add Vehicle
C Compute License Fee
D Count Certain Vehicles
L List Vehicles
Q Quit
? Display Help
What action would you like to perform?
l
NEW Vehicle:
Make: GM
Model Year: 2016
Motive Power: gas
License Fee: $3920.075
Price: $25000.5
Choice Action
------ ------
A Add Vehicle
C Compute License Fee
D Count Certain Vehicles
L List Vehicles
Q Quit
? Display Help
What action would you like to perform?
q

More Related Content

Similar to publicclass VehicleParser {publicstatic Vehicle parseStringToVehic.pdf

Simple array Java code.The “Park-a-lot” parking garage currently o.pdf
Simple array Java code.The “Park-a-lot” parking garage currently o.pdfSimple array Java code.The “Park-a-lot” parking garage currently o.pdf
Simple array Java code.The “Park-a-lot” parking garage currently o.pdffasttracktreding
 
Software Engineer Screening Question - OOP
Software Engineer Screening Question - OOPSoftware Engineer Screening Question - OOP
Software Engineer Screening Question - OOPjason_scorebig
 
public class Passenger {    public static enum Section {        .pdf
public class Passenger {    public static enum Section {        .pdfpublic class Passenger {    public static enum Section {        .pdf
public class Passenger {    public static enum Section {        .pdfannesmkt
 
C#i need help creating the instance of stream reader to read from .pdf
C#i need help creating the instance of stream reader to read from .pdfC#i need help creating the instance of stream reader to read from .pdf
C#i need help creating the instance of stream reader to read from .pdfajantha11
 
FedExPlanes7.txt1 medical 111 Boeing767 120000 London 3 packages.pdf
FedExPlanes7.txt1 medical 111 Boeing767 120000 London 3 packages.pdfFedExPlanes7.txt1 medical 111 Boeing767 120000 London 3 packages.pdf
FedExPlanes7.txt1 medical 111 Boeing767 120000 London 3 packages.pdfalukkasprince
 
I need to do the followingAdd a new item to the inventory m.pdf
I need to do the followingAdd a new item to the inventory m.pdfI need to do the followingAdd a new item to the inventory m.pdf
I need to do the followingAdd a new item to the inventory m.pdfadianantsolutions
 
Goal The goal of this assignment is to help students understand the.pdf
Goal The goal of this assignment is to help students understand the.pdfGoal The goal of this assignment is to help students understand the.pdf
Goal The goal of this assignment is to help students understand the.pdfarsmobiles
 
Predicting model for prices of used cars
Predicting model for prices of used carsPredicting model for prices of used cars
Predicting model for prices of used carsHARPREETSINGH1862
 
Vehicle.javapublic class Vehicle {    Declaring instance var.pdf
Vehicle.javapublic class Vehicle {    Declaring instance var.pdfVehicle.javapublic class Vehicle {    Declaring instance var.pdf
Vehicle.javapublic class Vehicle {    Declaring instance var.pdfanujsharmaanuj14
 
Creating an Uber Clone - Part XXVI - Transcript.pdf
Creating an Uber Clone - Part XXVI - Transcript.pdfCreating an Uber Clone - Part XXVI - Transcript.pdf
Creating an Uber Clone - Part XXVI - Transcript.pdfShaiAlmog1
 
computer project by sandhya ,shital,himanshi.pptx
computer project by sandhya ,shital,himanshi.pptxcomputer project by sandhya ,shital,himanshi.pptx
computer project by sandhya ,shital,himanshi.pptxIshooYadav
 
Scala Self Types by Gregor Heine, Principal Software Engineer at Gilt
Scala Self Types by Gregor Heine, Principal Software Engineer at GiltScala Self Types by Gregor Heine, Principal Software Engineer at Gilt
Scala Self Types by Gregor Heine, Principal Software Engineer at GiltGilt Tech Talks
 
In this assignment you will practice creating classes and enumeratio.pdf
In this assignment you will practice creating classes and enumeratio.pdfIn this assignment you will practice creating classes and enumeratio.pdf
In this assignment you will practice creating classes and enumeratio.pdfivylinvaydak64229
 
Create a system to simulate vehicles at an intersection. Assume th.pdf
Create a system to simulate vehicles at an intersection. Assume th.pdfCreate a system to simulate vehicles at an intersection. Assume th.pdf
Create a system to simulate vehicles at an intersection. Assume th.pdfarchanacomputers1
 
Programimport java.util.; import java.io.; class FoodTruck.pdf
Programimport java.util.; import java.io.; class FoodTruck.pdfProgramimport java.util.; import java.io.; class FoodTruck.pdf
Programimport java.util.; import java.io.; class FoodTruck.pdfapleathers
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
#includeiostream #includecmath #includestringusing na.pdf
 #includeiostream #includecmath #includestringusing na.pdf #includeiostream #includecmath #includestringusing na.pdf
#includeiostream #includecmath #includestringusing na.pdfanuradhaartjwellery
 
Angular2: Quick overview with 2do app example
Angular2: Quick overview with 2do app exampleAngular2: Quick overview with 2do app example
Angular2: Quick overview with 2do app exampleAlexey Frolov
 

Similar to publicclass VehicleParser {publicstatic Vehicle parseStringToVehic.pdf (19)

Simple array Java code.The “Park-a-lot” parking garage currently o.pdf
Simple array Java code.The “Park-a-lot” parking garage currently o.pdfSimple array Java code.The “Park-a-lot” parking garage currently o.pdf
Simple array Java code.The “Park-a-lot” parking garage currently o.pdf
 
Software Engineer Screening Question - OOP
Software Engineer Screening Question - OOPSoftware Engineer Screening Question - OOP
Software Engineer Screening Question - OOP
 
public class Passenger {    public static enum Section {        .pdf
public class Passenger {    public static enum Section {        .pdfpublic class Passenger {    public static enum Section {        .pdf
public class Passenger {    public static enum Section {        .pdf
 
C#i need help creating the instance of stream reader to read from .pdf
C#i need help creating the instance of stream reader to read from .pdfC#i need help creating the instance of stream reader to read from .pdf
C#i need help creating the instance of stream reader to read from .pdf
 
FedExPlanes7.txt1 medical 111 Boeing767 120000 London 3 packages.pdf
FedExPlanes7.txt1 medical 111 Boeing767 120000 London 3 packages.pdfFedExPlanes7.txt1 medical 111 Boeing767 120000 London 3 packages.pdf
FedExPlanes7.txt1 medical 111 Boeing767 120000 London 3 packages.pdf
 
I need to do the followingAdd a new item to the inventory m.pdf
I need to do the followingAdd a new item to the inventory m.pdfI need to do the followingAdd a new item to the inventory m.pdf
I need to do the followingAdd a new item to the inventory m.pdf
 
C# Programming Help
C# Programming HelpC# Programming Help
C# Programming Help
 
Goal The goal of this assignment is to help students understand the.pdf
Goal The goal of this assignment is to help students understand the.pdfGoal The goal of this assignment is to help students understand the.pdf
Goal The goal of this assignment is to help students understand the.pdf
 
Predicting model for prices of used cars
Predicting model for prices of used carsPredicting model for prices of used cars
Predicting model for prices of used cars
 
Vehicle.javapublic class Vehicle {    Declaring instance var.pdf
Vehicle.javapublic class Vehicle {    Declaring instance var.pdfVehicle.javapublic class Vehicle {    Declaring instance var.pdf
Vehicle.javapublic class Vehicle {    Declaring instance var.pdf
 
Creating an Uber Clone - Part XXVI - Transcript.pdf
Creating an Uber Clone - Part XXVI - Transcript.pdfCreating an Uber Clone - Part XXVI - Transcript.pdf
Creating an Uber Clone - Part XXVI - Transcript.pdf
 
computer project by sandhya ,shital,himanshi.pptx
computer project by sandhya ,shital,himanshi.pptxcomputer project by sandhya ,shital,himanshi.pptx
computer project by sandhya ,shital,himanshi.pptx
 
Scala Self Types by Gregor Heine, Principal Software Engineer at Gilt
Scala Self Types by Gregor Heine, Principal Software Engineer at GiltScala Self Types by Gregor Heine, Principal Software Engineer at Gilt
Scala Self Types by Gregor Heine, Principal Software Engineer at Gilt
 
In this assignment you will practice creating classes and enumeratio.pdf
In this assignment you will practice creating classes and enumeratio.pdfIn this assignment you will practice creating classes and enumeratio.pdf
In this assignment you will practice creating classes and enumeratio.pdf
 
Create a system to simulate vehicles at an intersection. Assume th.pdf
Create a system to simulate vehicles at an intersection. Assume th.pdfCreate a system to simulate vehicles at an intersection. Assume th.pdf
Create a system to simulate vehicles at an intersection. Assume th.pdf
 
Programimport java.util.; import java.io.; class FoodTruck.pdf
Programimport java.util.; import java.io.; class FoodTruck.pdfProgramimport java.util.; import java.io.; class FoodTruck.pdf
Programimport java.util.; import java.io.; class FoodTruck.pdf
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
#includeiostream #includecmath #includestringusing na.pdf
 #includeiostream #includecmath #includestringusing na.pdf #includeiostream #includecmath #includestringusing na.pdf
#includeiostream #includecmath #includestringusing na.pdf
 
Angular2: Quick overview with 2do app example
Angular2: Quick overview with 2do app exampleAngular2: Quick overview with 2do app example
Angular2: Quick overview with 2do app example
 

More from ANGELMARKETINGJAIPUR

they are not soluble in waterthey forms ions in t.pdf
                     they are not soluble in waterthey forms ions in t.pdf                     they are not soluble in waterthey forms ions in t.pdf
they are not soluble in waterthey forms ions in t.pdfANGELMARKETINGJAIPUR
 
Non metals generally want to gain electrons and a.pdf
                     Non metals generally want to gain electrons and a.pdf                     Non metals generally want to gain electrons and a.pdf
Non metals generally want to gain electrons and a.pdfANGELMARKETINGJAIPUR
 
London force the attraction between two rapidly .pdf
                     London force the attraction between two rapidly .pdf                     London force the attraction between two rapidly .pdf
London force the attraction between two rapidly .pdfANGELMARKETINGJAIPUR
 
HNO3 is a strong mono-protic acid. This means it .pdf
                     HNO3 is a strong mono-protic acid. This means it .pdf                     HNO3 is a strong mono-protic acid. This means it .pdf
HNO3 is a strong mono-protic acid. This means it .pdfANGELMARKETINGJAIPUR
 
H2Se (hydrogen (I) selenide) Boiling point -42°.pdf
                     H2Se (hydrogen (I) selenide)  Boiling point -42°.pdf                     H2Se (hydrogen (I) selenide)  Boiling point -42°.pdf
H2Se (hydrogen (I) selenide) Boiling point -42°.pdfANGELMARKETINGJAIPUR
 
Enthalphy for HCl would be more as acetic acid is.pdf
                     Enthalphy for HCl would be more as acetic acid is.pdf                     Enthalphy for HCl would be more as acetic acid is.pdf
Enthalphy for HCl would be more as acetic acid is.pdfANGELMARKETINGJAIPUR
 
Valid implication. The primary two properties suggest babies are hat.pdf
Valid implication. The primary two properties suggest babies are hat.pdfValid implication. The primary two properties suggest babies are hat.pdf
Valid implication. The primary two properties suggest babies are hat.pdfANGELMARKETINGJAIPUR
 
Think about the core ideas (themes, motifs, lessons) of Harrison Ber.pdf
Think about the core ideas (themes, motifs, lessons) of Harrison Ber.pdfThink about the core ideas (themes, motifs, lessons) of Harrison Ber.pdf
Think about the core ideas (themes, motifs, lessons) of Harrison Ber.pdfANGELMARKETINGJAIPUR
 
the series divergesSolutionthe series diverges.pdf
the series divergesSolutionthe series diverges.pdfthe series divergesSolutionthe series diverges.pdf
the series divergesSolutionthe series diverges.pdfANGELMARKETINGJAIPUR
 
The fate of pyruvate depends on the availability of oxygen.Three fat.pdf
The fate of pyruvate depends on the availability of oxygen.Three fat.pdfThe fate of pyruvate depends on the availability of oxygen.Three fat.pdf
The fate of pyruvate depends on the availability of oxygen.Three fat.pdfANGELMARKETINGJAIPUR
 
Covalent Bond - Two atoms Share electrons Polar .pdf
                     Covalent Bond - Two atoms Share electrons  Polar .pdf                     Covalent Bond - Two atoms Share electrons  Polar .pdf
Covalent Bond - Two atoms Share electrons Polar .pdfANGELMARKETINGJAIPUR
 
Since Calcuium hydroxide has a very strong dissassociation forevery .pdf
Since Calcuium hydroxide has a very strong dissassociation forevery .pdfSince Calcuium hydroxide has a very strong dissassociation forevery .pdf
Since Calcuium hydroxide has a very strong dissassociation forevery .pdfANGELMARKETINGJAIPUR
 
Shouldnt it just be the same answer as b The rate at which NO2 an.pdf
Shouldnt it just be the same answer as b The rate at which NO2 an.pdfShouldnt it just be the same answer as b The rate at which NO2 an.pdf
Shouldnt it just be the same answer as b The rate at which NO2 an.pdfANGELMARKETINGJAIPUR
 
Point.h header file #ifndef POINT_H #define POINT_H Po.pdf
Point.h header file #ifndef POINT_H #define POINT_H Po.pdfPoint.h header file #ifndef POINT_H #define POINT_H Po.pdf
Point.h header file #ifndef POINT_H #define POINT_H Po.pdfANGELMARKETINGJAIPUR
 
Preliminary Engagement activity includePlanning activities involv.pdf
Preliminary Engagement activity includePlanning activities involv.pdfPreliminary Engagement activity includePlanning activities involv.pdf
Preliminary Engagement activity includePlanning activities involv.pdfANGELMARKETINGJAIPUR
 
please give some additional informationSolutionplease give som.pdf
please give some additional informationSolutionplease give som.pdfplease give some additional informationSolutionplease give som.pdf
please give some additional informationSolutionplease give som.pdfANGELMARKETINGJAIPUR
 
Macaulay duration = [tC(1+y)t + nM(1+y)nP]                     .pdf
Macaulay duration = [tC(1+y)t + nM(1+y)nP]                     .pdfMacaulay duration = [tC(1+y)t + nM(1+y)nP]                     .pdf
Macaulay duration = [tC(1+y)t + nM(1+y)nP]                     .pdfANGELMARKETINGJAIPUR
 
Hi!For hydrogen fluoride the predominant intermolecular force is .pdf
Hi!For hydrogen fluoride the predominant intermolecular force is .pdfHi!For hydrogen fluoride the predominant intermolecular force is .pdf
Hi!For hydrogen fluoride the predominant intermolecular force is .pdfANGELMARKETINGJAIPUR
 

More from ANGELMARKETINGJAIPUR (20)

they are not soluble in waterthey forms ions in t.pdf
                     they are not soluble in waterthey forms ions in t.pdf                     they are not soluble in waterthey forms ions in t.pdf
they are not soluble in waterthey forms ions in t.pdf
 
Non metals generally want to gain electrons and a.pdf
                     Non metals generally want to gain electrons and a.pdf                     Non metals generally want to gain electrons and a.pdf
Non metals generally want to gain electrons and a.pdf
 
London force the attraction between two rapidly .pdf
                     London force the attraction between two rapidly .pdf                     London force the attraction between two rapidly .pdf
London force the attraction between two rapidly .pdf
 
HNO3 is a strong mono-protic acid. This means it .pdf
                     HNO3 is a strong mono-protic acid. This means it .pdf                     HNO3 is a strong mono-protic acid. This means it .pdf
HNO3 is a strong mono-protic acid. This means it .pdf
 
H2Se (hydrogen (I) selenide) Boiling point -42°.pdf
                     H2Se (hydrogen (I) selenide)  Boiling point -42°.pdf                     H2Se (hydrogen (I) selenide)  Boiling point -42°.pdf
H2Se (hydrogen (I) selenide) Boiling point -42°.pdf
 
Enthalphy for HCl would be more as acetic acid is.pdf
                     Enthalphy for HCl would be more as acetic acid is.pdf                     Enthalphy for HCl would be more as acetic acid is.pdf
Enthalphy for HCl would be more as acetic acid is.pdf
 
e.) none of these .pdf
                     e.) none of these                                .pdf                     e.) none of these                                .pdf
e.) none of these .pdf
 
Valid implication. The primary two properties suggest babies are hat.pdf
Valid implication. The primary two properties suggest babies are hat.pdfValid implication. The primary two properties suggest babies are hat.pdf
Valid implication. The primary two properties suggest babies are hat.pdf
 
Think about the core ideas (themes, motifs, lessons) of Harrison Ber.pdf
Think about the core ideas (themes, motifs, lessons) of Harrison Ber.pdfThink about the core ideas (themes, motifs, lessons) of Harrison Ber.pdf
Think about the core ideas (themes, motifs, lessons) of Harrison Ber.pdf
 
the series divergesSolutionthe series diverges.pdf
the series divergesSolutionthe series diverges.pdfthe series divergesSolutionthe series diverges.pdf
the series divergesSolutionthe series diverges.pdf
 
The fate of pyruvate depends on the availability of oxygen.Three fat.pdf
The fate of pyruvate depends on the availability of oxygen.Three fat.pdfThe fate of pyruvate depends on the availability of oxygen.Three fat.pdf
The fate of pyruvate depends on the availability of oxygen.Three fat.pdf
 
Covalent Bond - Two atoms Share electrons Polar .pdf
                     Covalent Bond - Two atoms Share electrons  Polar .pdf                     Covalent Bond - Two atoms Share electrons  Polar .pdf
Covalent Bond - Two atoms Share electrons Polar .pdf
 
Since Calcuium hydroxide has a very strong dissassociation forevery .pdf
Since Calcuium hydroxide has a very strong dissassociation forevery .pdfSince Calcuium hydroxide has a very strong dissassociation forevery .pdf
Since Calcuium hydroxide has a very strong dissassociation forevery .pdf
 
Shouldnt it just be the same answer as b The rate at which NO2 an.pdf
Shouldnt it just be the same answer as b The rate at which NO2 an.pdfShouldnt it just be the same answer as b The rate at which NO2 an.pdf
Shouldnt it just be the same answer as b The rate at which NO2 an.pdf
 
Point.h header file #ifndef POINT_H #define POINT_H Po.pdf
Point.h header file #ifndef POINT_H #define POINT_H Po.pdfPoint.h header file #ifndef POINT_H #define POINT_H Po.pdf
Point.h header file #ifndef POINT_H #define POINT_H Po.pdf
 
Preliminary Engagement activity includePlanning activities involv.pdf
Preliminary Engagement activity includePlanning activities involv.pdfPreliminary Engagement activity includePlanning activities involv.pdf
Preliminary Engagement activity includePlanning activities involv.pdf
 
please give some additional informationSolutionplease give som.pdf
please give some additional informationSolutionplease give som.pdfplease give some additional informationSolutionplease give som.pdf
please give some additional informationSolutionplease give som.pdf
 
parabolaSolutionparabola.pdf
parabolaSolutionparabola.pdfparabolaSolutionparabola.pdf
parabolaSolutionparabola.pdf
 
Macaulay duration = [tC(1+y)t + nM(1+y)nP]                     .pdf
Macaulay duration = [tC(1+y)t + nM(1+y)nP]                     .pdfMacaulay duration = [tC(1+y)t + nM(1+y)nP]                     .pdf
Macaulay duration = [tC(1+y)t + nM(1+y)nP]                     .pdf
 
Hi!For hydrogen fluoride the predominant intermolecular force is .pdf
Hi!For hydrogen fluoride the predominant intermolecular force is .pdfHi!For hydrogen fluoride the predominant intermolecular force is .pdf
Hi!For hydrogen fluoride the predominant intermolecular force is .pdf
 

Recently uploaded

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 

Recently uploaded (20)

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 

publicclass VehicleParser {publicstatic Vehicle parseStringToVehic.pdf

  • 1. publicclass VehicleParser { publicstatic Vehicle parseStringToVehicle(String lineToParse) { String[] vehicleInfo = lineToParse.split("/"); if(vehicleInfo[0].equalsIgnoreCase("NewVehicle")) { //type/make/modelYear/motivePower/vehiclePrice returnnew NewVehicle(vehicleInfo[1], Integer.parseInt(vehicleInfo[2]), vehicleInfo[3], Double.parseDouble(vehicleInfo[4])); } elseif(vehicleInfo[0].equalsIgnoreCase("UsedVehicle")) { //type/make/modelYear/motivePower/previousState/currentYear returnnew UsedVehicle(vehicleInfo[1], Integer.parseInt(vehicleInfo[2]), vehicleInfo[3], vehicleInfo[4], Integer.parseInt(vehicleInfo[5])); } returnnull; } } publicabstractclass Vehicle { //Attributes protected String make; protectedint modelYear; protected String motivePower; protecteddouble licenseFee; /** * Constructor * @param make * @param modelYear * @param motivePower */ public Vehicle(String make, int modelYear, String motivePower) { this.make = make; this.modelYear = modelYear;
  • 2. this.motivePower = motivePower; this.licenseFee = 0.0; } /** * @return the modelYear */ publicint getModelYear() { return modelYear; } @Override public String toString() { return " Make:tt" + this.make + " Model Year:t" + this.modelYear + " Motive Power:t" + this.motivePower + " License Fee:t$" + this.licenseFee + " "; } publicabstractvoid computeLicenseFee(); } publicclass NewVehicle extends Vehicle { privatestaticdoubleBASE_FEE = 150.00; privatestaticdoublePRICE_FEE = 0.15; //Attributes privatedouble vehiclePrice; /** * Constructor * @param make * @param modelYear * @param motivePower * @param vehiclePrice */ public NewVehicle(String make, int modelYear, String motivePower, double vehiclePrice) { super(make, modelYear, motivePower); this.vehiclePrice = vehiclePrice; } @Override publicvoid computeLicenseFee() {
  • 3. double smogAbatement = 0.0; if(motivePower.equalsIgnoreCase("gas")) smogAbatement = 20.00; licenseFee = BASE_FEE + smogAbatement + (this.vehiclePrice * PRICE_FEE); } @Override public String toString() { return " NEW Vehicle:" + super.toString() + "Price:tt$" + this.vehiclePrice + " "; } } publicclass UsedVehicle extends Vehicle { privatestaticdoubleBASE_FEE = 100.00; privatestaticdoubleTITLE_TRANSFER_FEE = 15.00; //Attributes private String previousLicenseState; privateint currentYear; public UsedVehicle(String make, int modelYear, String motivePower, String previousLicenseState, int currentYear) { super(make, modelYear, motivePower); this.previousLicenseState = previousLicenseState; this.currentYear = currentYear; } @Override publicvoid computeLicenseFee() { double smogWaiverFee = 0.0; if((this.currentYear - this.modelYear) >= 5) smogWaiverFee = 8.00; double smogAbatement = 0.0; if(motivePower.equalsIgnoreCase("gas")) smogAbatement = 20.00; licenseFee = BASE_FEE + smogAbatement + TITLE_TRANSFER_FEE + smogWaiverFee; } @Override public String toString() {
  • 4. return " USED Vehicle:" + super.toString() + "Years Old:t" + (this.currentYear - this.modelYear) + " Previous State:t" + this.previousLicenseState + " "; } } import java.util.ArrayList; import java.util.List; import java.util.Scanner; publicclass Assignment5 { static Scanner scanner = new Scanner(System.in); /** * Clear keyboard buffer */ publicstaticvoid clearBuf(){ scanner.nextLine(); } /** * Prints the menu */ publicstaticvoid displayMenu(){ System.out.println("ChoicettAction "); System.out.println("------tt------ "); System.out.println("AttAdd Vehicle "); System.out.println("CttCompute License Fee "); System.out.println("DttCount Certain Vehicles "); System.out.println("LttList Vehicles "); System.out.println("QttQuit "); System.out.println("?ttDisplay Help "); System.out.println("What action would you like to perform? "); } publicstaticvoid main(String args[]) { List vehicleList= new ArrayList(); char choice = ' '; while(true) { displayMenu();
  • 5. choice = Character.toUpperCase(scanner.next().charAt(0)); clearBuf(); switch (choice) { case 'A': //Add Vehicle System.out.println("Please enter some vehicle information to add: "); Vehicle vehicle = VehicleParser.parseStringToVehicle(scanner.nextLine()); if(vehicle != null) vehicleList.add(vehicle); break; case 'C': //Compute License Fee for (Vehicle veh : vehicleList) { veh.computeLicenseFee(); } System.out.println("License fee computed "); break; case 'D': //Count Certain Vehicles System.out.println("Please enter a year to compare: "); int year = scanner.nextInt(); clearBuf(); int vehCount = 0; for (Vehicle veh : vehicleList) { if(veh.modelYear > year) vehCount += 1; } System.out.println("The number of vehicles that are newer than " + year + " is: " + vehCount + " "); break; case 'L': //List Vehicles if(vehicleList.size() > 0) { for (Vehicle veh : vehicleList) { System.out.println(veh); } } else System.out.println("No vehicle "); break; case 'Q': //Quit
  • 6. System.exit(0); break; case '?': //Display Help break; default: System.out.println("Unknown action "); } } } } SAMPLE OUTPUT: Choice Action ------ ------ A Add Vehicle C Compute License Fee D Count Certain Vehicles L List Vehicles Q Quit ? Display Help What action would you like to perform? e Unknown action Choice Action ------ ------ A Add Vehicle C Compute License Fee D Count Certain Vehicles L List Vehicles Q Quit ? Display Help What action would you like to perform? l No vehicle Choice Action
  • 7. ------ ------ A Add Vehicle C Compute License Fee D Count Certain Vehicles L List Vehicles Q Quit ? Display Help What action would you like to perform? a Please enter some vehicle information to add: NewVehicle/GM/2016/gas/25000.50 Choice Action ------ ------ A Add Vehicle C Compute License Fee D Count Certain Vehicles L List Vehicles Q Quit ? Display Help What action would you like to perform? c License fee computed Choice Action ------ ------ A Add Vehicle C Compute License Fee D Count Certain Vehicles L List Vehicles Q Quit ? Display Help What action would you like to perform? l NEW Vehicle:
  • 8. Make: GM Model Year: 2016 Motive Power: gas License Fee: $3920.075 Price: $25000.5 Choice Action ------ ------ A Add Vehicle C Compute License Fee D Count Certain Vehicles L List Vehicles Q Quit ? Display Help What action would you like to perform? q Solution publicclass VehicleParser { publicstatic Vehicle parseStringToVehicle(String lineToParse) { String[] vehicleInfo = lineToParse.split("/"); if(vehicleInfo[0].equalsIgnoreCase("NewVehicle")) { //type/make/modelYear/motivePower/vehiclePrice returnnew NewVehicle(vehicleInfo[1], Integer.parseInt(vehicleInfo[2]), vehicleInfo[3], Double.parseDouble(vehicleInfo[4])); } elseif(vehicleInfo[0].equalsIgnoreCase("UsedVehicle")) { //type/make/modelYear/motivePower/previousState/currentYear returnnew UsedVehicle(vehicleInfo[1], Integer.parseInt(vehicleInfo[2]), vehicleInfo[3], vehicleInfo[4], Integer.parseInt(vehicleInfo[5]));
  • 9. } returnnull; } } publicabstractclass Vehicle { //Attributes protected String make; protectedint modelYear; protected String motivePower; protecteddouble licenseFee; /** * Constructor * @param make * @param modelYear * @param motivePower */ public Vehicle(String make, int modelYear, String motivePower) { this.make = make; this.modelYear = modelYear; this.motivePower = motivePower; this.licenseFee = 0.0; } /** * @return the modelYear */ publicint getModelYear() { return modelYear; } @Override public String toString() { return " Make:tt" + this.make + " Model Year:t" + this.modelYear + " Motive Power:t" + this.motivePower + " License Fee:t$" + this.licenseFee + " "; } publicabstractvoid computeLicenseFee();
  • 10. } publicclass NewVehicle extends Vehicle { privatestaticdoubleBASE_FEE = 150.00; privatestaticdoublePRICE_FEE = 0.15; //Attributes privatedouble vehiclePrice; /** * Constructor * @param make * @param modelYear * @param motivePower * @param vehiclePrice */ public NewVehicle(String make, int modelYear, String motivePower, double vehiclePrice) { super(make, modelYear, motivePower); this.vehiclePrice = vehiclePrice; } @Override publicvoid computeLicenseFee() { double smogAbatement = 0.0; if(motivePower.equalsIgnoreCase("gas")) smogAbatement = 20.00; licenseFee = BASE_FEE + smogAbatement + (this.vehiclePrice * PRICE_FEE); } @Override public String toString() { return " NEW Vehicle:" + super.toString() + "Price:tt$" + this.vehiclePrice + " "; } } publicclass UsedVehicle extends Vehicle { privatestaticdoubleBASE_FEE = 100.00; privatestaticdoubleTITLE_TRANSFER_FEE = 15.00; //Attributes private String previousLicenseState;
  • 11. privateint currentYear; public UsedVehicle(String make, int modelYear, String motivePower, String previousLicenseState, int currentYear) { super(make, modelYear, motivePower); this.previousLicenseState = previousLicenseState; this.currentYear = currentYear; } @Override publicvoid computeLicenseFee() { double smogWaiverFee = 0.0; if((this.currentYear - this.modelYear) >= 5) smogWaiverFee = 8.00; double smogAbatement = 0.0; if(motivePower.equalsIgnoreCase("gas")) smogAbatement = 20.00; licenseFee = BASE_FEE + smogAbatement + TITLE_TRANSFER_FEE + smogWaiverFee; } @Override public String toString() { return " USED Vehicle:" + super.toString() + "Years Old:t" + (this.currentYear - this.modelYear) + " Previous State:t" + this.previousLicenseState + " "; } } import java.util.ArrayList; import java.util.List; import java.util.Scanner; publicclass Assignment5 { static Scanner scanner = new Scanner(System.in); /** * Clear keyboard buffer */ publicstaticvoid clearBuf(){ scanner.nextLine(); }
  • 12. /** * Prints the menu */ publicstaticvoid displayMenu(){ System.out.println("ChoicettAction "); System.out.println("------tt------ "); System.out.println("AttAdd Vehicle "); System.out.println("CttCompute License Fee "); System.out.println("DttCount Certain Vehicles "); System.out.println("LttList Vehicles "); System.out.println("QttQuit "); System.out.println("?ttDisplay Help "); System.out.println("What action would you like to perform? "); } publicstaticvoid main(String args[]) { List vehicleList= new ArrayList(); char choice = ' '; while(true) { displayMenu(); choice = Character.toUpperCase(scanner.next().charAt(0)); clearBuf(); switch (choice) { case 'A': //Add Vehicle System.out.println("Please enter some vehicle information to add: "); Vehicle vehicle = VehicleParser.parseStringToVehicle(scanner.nextLine()); if(vehicle != null) vehicleList.add(vehicle); break; case 'C': //Compute License Fee for (Vehicle veh : vehicleList) { veh.computeLicenseFee(); } System.out.println("License fee computed "); break; case 'D': //Count Certain Vehicles System.out.println("Please enter a year to compare: ");
  • 13. int year = scanner.nextInt(); clearBuf(); int vehCount = 0; for (Vehicle veh : vehicleList) { if(veh.modelYear > year) vehCount += 1; } System.out.println("The number of vehicles that are newer than " + year + " is: " + vehCount + " "); break; case 'L': //List Vehicles if(vehicleList.size() > 0) { for (Vehicle veh : vehicleList) { System.out.println(veh); } } else System.out.println("No vehicle "); break; case 'Q': //Quit System.exit(0); break; case '?': //Display Help break; default: System.out.println("Unknown action "); } } } } SAMPLE OUTPUT: Choice Action ------ ------ A Add Vehicle C Compute License Fee D Count Certain Vehicles L List Vehicles
  • 14. Q Quit ? Display Help What action would you like to perform? e Unknown action Choice Action ------ ------ A Add Vehicle C Compute License Fee D Count Certain Vehicles L List Vehicles Q Quit ? Display Help What action would you like to perform? l No vehicle Choice Action ------ ------ A Add Vehicle C Compute License Fee D Count Certain Vehicles L List Vehicles Q Quit ? Display Help What action would you like to perform? a Please enter some vehicle information to add: NewVehicle/GM/2016/gas/25000.50 Choice Action ------ ------ A Add Vehicle C Compute License Fee D Count Certain Vehicles
  • 15. L List Vehicles Q Quit ? Display Help What action would you like to perform? c License fee computed Choice Action ------ ------ A Add Vehicle C Compute License Fee D Count Certain Vehicles L List Vehicles Q Quit ? Display Help What action would you like to perform? l NEW Vehicle: Make: GM Model Year: 2016 Motive Power: gas License Fee: $3920.075 Price: $25000.5 Choice Action ------ ------ A Add Vehicle C Compute License Fee D Count Certain Vehicles L List Vehicles Q Quit ? Display Help What action would you like to perform? q