Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Hi I'm desperate for help with this assignment. I worked on it at the bottom of the assignment is my work. Can you tell me how I am doing and if im doing something wrong can you correct me or give me a few pointers, point me in the right direction please. Wb asap I have till Sunday Morning to come up with answers and finish this.
- Design classes that reflect vehicle, car, american car, foreign car, truck, and bicycle with ALL appropriate inheritances.
- vehicle is the parent.
- Your code must override the toString method in each class to display ALL the relevant information from the record.
- Also design an application with a main that tests your classes and processes a file of records (main is specified later).
- I will run your compiled code and run your client program using jGrasp.
- The file of data to be used from the menu system has the following format:
- vehicle (fixed)
- owner's name (string)
- address (string)
- phone (string)
- email (string)
- car (fixed)
- owner's name (string)
- address (string)
- phone (string)
- email (string)
- true or false for convertible (boolean)
- color (string)
- american car (fixed)
- owner's name (string)
- address (string)
- phone (string)
- email (string)
- true or false for convertible (boolean)
- color (string)
- true or false for made in Detroit (boolean)
- true or false for union shop (boolean)
- foreign car (fixed)
- owner's name (string)
- address (string)
- phone (string)
- email (string)
- true or false for convertible (boolean)
- color (string)
- country of manufacturer (string)
- import duty (float)
- bicycle (fixed)
- owner's name (string)
- address (string)
- phone (string)
- email (string)
- # of speeds (int)
- truck (fixed)
- owner's name (string)
- address (string)
- phone (string)
- email (string)
- # of tons (float)
- cost of truck (float)
- date purchased (java.util.Date)
- etc.....these records can appear in any order and there can be any number of them.
- IF YOU CAN'T FIGURE OUT HOW TO ALLOW ANY NUMBER OF RECORDS, YOU CAN ASSUME THAT THERE WILL BE NO MORE
- THAN 20 RECORDS, BUT THERE WILL BE A 5 POINT DEDUCT FOR THAT RESTRICTION. MY SUGGESTION WOULD BE TO CODE FOR 100
- RECORDS, AND THEN HAVE A METHOD THAT DOUBLES THE SIZE TO 200, THEN 400, THEN 800, ETC, IF YOU EVER NEED IT.
- PLEASE SPECIFY AT THE TOP OF YOUR DOCUMENTATION WHETHER YOU ALLOW ANY NUMBER OF RECORDS.
- Each record will have a line that identifies its type and then on separate lines will be the data.
- Records will have a blank line between them.
- You will need to use an array of Vechicles to store the data.
- Here are some examples of data:
- foreign car
- aMarioy
- Mario's house
- (777) 777-7777
- gmario@mario.com
- false
- black
- Italy
- 4415.91
- truck
- aDougy
- Doug's house
- (123) 456-7890
- hdoug@doug.com
- 30
- 61234.56
- 8/10/2003
- vehicle
- aRobby
- Rob's house
- (987) 654-3210
- irob@rob.com
- bicycle
- bTommy
- Tom's house
- (246) 810-1214
- jtom@tom.com
- 7
- truck
- bGeorge
- George's house
- (666) 666-6666
- kgeorge@george.com
- 25
- 51234.56
- 12/4/2004
- vehicle
- bTim
- Tim's house
- (111) 111-1111
- tim@tim.com
- bicycle
- bJim
- Jim's house
- (555) 555-5555
- Ajim@jim.com
- 5
- american car
- bJohn
- John's house
- (888) 888-8888
- Bjohn@john.com
- true
- green
- false
- true
- car
- cKen
- Ken's house
- (999) 999-9999
- Cken@ken.com
- false
- orange
- foreign car
- cMario
- Mario's house
- (777) 777-7777
- Dmario@mario.com
- false
- black
- Italy
- 4415.91
- truck
- zDoug
- Doug's house
- (123) 456-7890
- Edoug@doug.com
- 30
- 61234.56
- 8/10/2003
- vehicle
- eRob
- Rob's house
- (987) 654-3210
- Frob@rob.com
- bicycle
- fTom
- Tom's house
- (246) 810-1214
- Gtom@tom.com
- 7
- american car
- gSam
- Sam's house
- (333) 333-3333
- Hsam@sam.com
- false
- blue
- true
- false
- Write an application with a main that reads a file (from the command line) and fills an array of type vehicle[] with new vehicle
- (params), new car (params), new american car (params) new foreign car(params) , new truck (params),
- new bicycle (params), etc. depending on the first line that identifies each record.
- Then it has a menu system that has the following features (THE MENU ITEMS SHOULD BE ABLE TO BE CHOSEN IN ANY ORDER
- AND CONTINUOUSLY UNTIL THE USER ENTERS THE WORD STOP):
- 1. Calls a printAll method that can be passed an array of type vehicle[] and which prints each element of
- the array using the appropriate toString() methods. ArrayList is fine if you wish to use it.
- 2. Calls a sort method that can be passed an array of type vehicle[] and which sorts the array by email addresses
- and prints the new sorted array using appropriate toString() methods. Any sort method is fine, but it should
- sort according to unicode (case sensitive, that is to say that all upper case is before any lower case)!
- 3. Calls a method that prints the number of records.
- 4. Calls a method that prints just the bicycles and trucks (from the sorted array using the appropriate toString() methods).
- 5. Calls a method that prints the vehicles in area code 987.
- Be sure to declare variables as private, to extend all the classes appropriately, and to have the right constructors (using super where
- appropriate), and the getters and setters for ALL the variables. MUST SEND ALL THE OUTPUT FROM PRINTING TO THE CONSOLE, NOT TO A WINDOW.
- Here is my project so far:
- import java.util.*;
- import java.io.*;
- import java.lang.*;
- public class n00640944
- {
- public static void main( String[] args) throws Exception
- {
- int traceOfArray = 100;
- Vehicle[] vehicle = new Vehicle[traceOfArray];
- File file = null;
- // try
- // {
- file = new File(args[0]);
- FileReader Fr = new FileReader(file); //read file.
- BufferedReader Br = new BufferedReader(Fr);
- String read = Br.readLine();
- try{
- while (read != null)
- {
- //System.out.println(read);
- char x = read.charAt(0);
- // for(int i=0; i<vehicle.length; i++)
- //
- // {
- if(x=='v')
- vehicle[0] = new Vehicle(Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine());
- else if(x=='c')
- vehicle[1] = new Car(Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine());
- else
- break;
- //read = Br.readLine();
- }//while
- }//try
- catch(NullPointerException e){}
- // {
- // vehicle[0] = new Vehicle(Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine());
- //vehicle[i++] = new VehicleArray(Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine());
- // }
- // else if(x=='c')
- // {
- // vehicle[1] = new Car(Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine());
- //
- // }
- // else if(x=='a')
- // {
- // vehicle[2] = new AmericanCar(Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine(),Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine());
- // }
- // else if(x=='f')
- // {
- // vehicle[3] = new Vehicle(Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine());
- //
- // }
- // else if(x=='b')
- // {
- // vehicle[4]=new Bicycle(Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine());
- //
- // }
- // else if(x=='t')
- // {
- // vehicle[5]= new Truck(Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine(),Br.readLine(), Br.readLine(), Br.readLine());
- //
- // }
- // else
- // System.out.println("An error occured!");
- // }
- // }//end while
- // }//end try
- // catch(Exception e)//any exception
- // {
- // traceOfArray= traceOfArray*2;
- // Vehicle[] tempVehicle = new Vehicle[traceOfArray];
- // for (int i=0; i<vehicle.length; i++)
- // {
- // tempVehicle[i]= vehicle[i];
- // }
- // }
- }// end main
- }//end class noo640944
- /******************************* class vehicle*****************************/
- class Vehicle
- {
- private String ownerName, address, phone, email;
- public Vehicle (String ownerName, String address, String phone, String email)
- {
- this.ownerName = ownerName;
- this.address = address;
- this.phone = phone;
- this.email = email;
- //System.out.println(ownerName+"\n"+ address+"\n"+ phone+"\n"+ email);
- }
- public String getName()
- { return ownerName; }
- public String getAddress()
- { return address;}
- public String getPhone()
- { return phone;}
- public String getEmail()
- { return email; }
- }//end class vehicle
- /********************* class bycicle **********************/
- public class Bicycle extends Vehicle
- {
- private String numOfSpeeds;
- public Bicycle(String ownerName, String address, String phone, String email, String numOfSpeeds)
- {
- super(ownerName, address, phone, email);
- this.numOfSpeeds= numOfSpeeds;
- }
- public String toString()
- {
- return super.toString()
- }
- }//end class Bycicle
- /********************* class Truck **********************/
- class Truck extends Vehicle
- {
- private String numOfTons, truckCost;
- private String datePurchased;
- public Truck( String numOfTons, ,String datePurchased)//second constructor
- {
- //datePurchased = new java.util.Date();
- this.datePurchased= datePurchased;
- this.numOfTons = numOfTons;
- this.truckCost= truckCost;
- }
- public Truck(String ownerName, String address, String phone, String email, String numOfTons, String truckCost)
- {
- //datePurchased = new java.util.Date();
- super(ownerName, address, phone, email);
- this.numOfTons= numOfTons;
- this.truckCost=truckCost;
- this.datePurchased= datePurchased;
- }
- public java.util.Date getDatePurchased()
- {
- return datePurchased;
- }
- }//end class Truck
- /********************* class car**********************/
- class Car extends Vehicle
- {
- private String color;
- private String convertible;
- public Car(String ownerName, String address, String phone, String email, String convertible, String color)
- {
- super(ownerName, address, phone, email);
- this.color = color;
- this.convertible = convertible;
- }
- public String toString()
- {
- return super.toString();
- }
- }//end class Car
- // /********************* class americanCar**********************/
- class AmericanCar extends Car
- {
- private String madeInDetroit, unionShop;
- public AmericanCar(String ownerName,String address,String phone,String email,boolean convertible,String color,String madeInDetroit,boolean unionShop)
- {
- super(ownerName,address,phone,email,convertible, color);
- this.madeInDetroit =madeInDetroit;
- this.unionShop = unionShop;
- }
- public String toString()
- {
- return super.toString();
- }
- }//end class americanCar
- /********************* class foreignCar**********************/
- class ForeignCar extends Car
- {
- private String manufacturerCountry;
- String importDuty;
- public ForeignCar(String ownerName,String address,String phone,String email,String convertible,String color,String manufacturerCountry,String importDuty)
- {
- super(ownerName,address,phone,email,convertible, color);
- this.manufacturerCountry=manufacturerCountry;
- this.importDuty=importDuty;
- }//end constructor
- public String toString()
- {
- return super.toString();
- }
- }//end class foreignCar
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement