Advertisement
Guest User

Untitled

a guest
Jun 21st, 2017
629
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.75 KB | None | 0 0
  1. 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.
  2. Design classes that reflect vehicle, car, american car, foreign car, truck, and bicycle with ALL appropriate inheritances.
  3. vehicle is the parent.
  4.  
  5. Your code must override the toString method in each class to display ALL the relevant information from the record.
  6. Also design an application with a main that tests your classes and processes a file of records (main is specified later).
  7.  
  8. I will run your compiled code  and run your client program using jGrasp.  
  9.  
  10. The file of data to be used from the menu system has the following format:
  11.  
  12. vehicle (fixed)
  13. owner's name (string)
  14. address (string)
  15. phone (string)
  16. email (string)
  17.  
  18. car (fixed)
  19. owner's name (string)
  20. address (string)
  21. phone (string)
  22. email (string)
  23. true or false for convertible (boolean)
  24. color (string)
  25.  
  26. american car (fixed)
  27. owner's name (string)
  28. address (string)
  29. phone (string)
  30. email (string)
  31. true or false for convertible (boolean)
  32. color (string)
  33. true or false for made in Detroit (boolean)
  34. true or false for union shop (boolean)
  35.  
  36. foreign car (fixed)
  37. owner's name (string)
  38. address (string)
  39. phone (string)
  40. email  (string)
  41. true or false for convertible (boolean)
  42. color (string)
  43. country of manufacturer (string)
  44. import duty (float)
  45.  
  46. bicycle (fixed)
  47. owner's name (string)
  48. address (string)
  49. phone (string)
  50. email (string)
  51. # of speeds (int)
  52.  
  53. truck (fixed)
  54. owner's name (string)
  55. address (string)
  56. phone (string)
  57. email (string)
  58. # of tons (float)
  59. cost of truck (float)
  60. date purchased (java.util.Date)
  61.  
  62.  
  63.  
  64.  
  65. etc.....these records can appear in any order and there can be any number of them.
  66. IF YOU CAN'T FIGURE OUT HOW TO ALLOW ANY NUMBER OF RECORDS, YOU CAN ASSUME THAT THERE WILL BE NO MORE
  67. THAN 20 RECORDS, BUT THERE WILL BE A 5 POINT DEDUCT FOR THAT RESTRICTION.  MY SUGGESTION WOULD BE TO CODE FOR 100
  68. RECORDS, AND THEN HAVE A METHOD THAT DOUBLES THE SIZE TO 200, THEN 400, THEN 800, ETC, IF YOU EVER NEED IT.
  69. PLEASE SPECIFY AT THE TOP OF YOUR DOCUMENTATION WHETHER YOU ALLOW ANY NUMBER OF RECORDS.
  70.  
  71. Each record will have a line that identifies its type and then on separate lines will be the data.
  72. Records will have a blank line between them.
  73. You will need to use an array of Vechicles to store the data.
  74.  
  75. Here are some examples of data:
  76.  
  77.  
  78. foreign car
  79. aMarioy
  80. Mario's house
  81. (777) 777-7777
  82. gmario@mario.com
  83. false
  84. black
  85. Italy
  86. 4415.91
  87.  
  88. truck
  89. aDougy
  90. Doug's house
  91. (123) 456-7890
  92. hdoug@doug.com
  93. 30
  94. 61234.56
  95. 8/10/2003
  96.  
  97. vehicle
  98. aRobby
  99. Rob's house
  100. (987) 654-3210
  101. irob@rob.com
  102.  
  103. bicycle
  104. bTommy
  105. Tom's house
  106. (246) 810-1214
  107. jtom@tom.com
  108. 7
  109.  
  110. truck
  111. bGeorge
  112. George's house
  113. (666) 666-6666
  114. kgeorge@george.com
  115. 25
  116. 51234.56
  117. 12/4/2004
  118.  
  119. vehicle
  120. bTim
  121. Tim's house
  122. (111) 111-1111
  123. tim@tim.com
  124.  
  125. bicycle
  126. bJim
  127. Jim's house
  128. (555) 555-5555
  129. Ajim@jim.com
  130. 5
  131.  
  132. american car
  133. bJohn
  134. John's house
  135. (888) 888-8888
  136. Bjohn@john.com
  137. true
  138. green
  139. false
  140. true
  141.  
  142. car
  143. cKen
  144. Ken's house
  145. (999) 999-9999
  146. Cken@ken.com
  147. false
  148. orange
  149.  
  150. foreign car
  151. cMario
  152. Mario's house
  153. (777) 777-7777
  154. Dmario@mario.com
  155. false
  156. black
  157. Italy
  158. 4415.91
  159.  
  160. truck
  161. zDoug
  162. Doug's house
  163. (123) 456-7890
  164. Edoug@doug.com
  165. 30
  166. 61234.56
  167. 8/10/2003
  168.  
  169. vehicle
  170. eRob
  171. Rob's house
  172. (987) 654-3210
  173. Frob@rob.com
  174.  
  175. bicycle
  176. fTom
  177. Tom's house
  178. (246) 810-1214
  179. Gtom@tom.com
  180. 7
  181.  
  182. american car
  183. gSam
  184. Sam's house
  185. (333) 333-3333
  186. Hsam@sam.com
  187. false
  188. blue
  189. true
  190. false
  191.  
  192.  
  193.  
  194. Write an application with a main that reads a file (from the command line) and fills an array of type vehicle[] with new vehicle
  195. (params), new car (params), new american car (params) new foreign car(params) , new truck (params),
  196. new bicycle (params), etc. depending on the first line that identifies each record.
  197.  
  198. Then it has a menu system that has the following features (THE MENU ITEMS SHOULD BE ABLE TO BE CHOSEN IN ANY ORDER
  199. AND CONTINUOUSLY UNTIL THE USER ENTERS THE WORD STOP):
  200.  
  201.  
  202.   1.  Calls a printAll method that can be passed an array of type vehicle[] and which prints each element of
  203.             the array using the appropriate toString() methods. ArrayList is fine if you wish to use it.
  204.  
  205.   2.  Calls a sort method that can be passed an array of type vehicle[] and which sorts the array by email addresses
  206.       and prints the new sorted array using appropriate toString() methods. Any sort method is fine, but it should
  207.             sort according to unicode (case sensitive, that is to say that all upper case is before any lower case)!
  208.  
  209.   3.  Calls a method that prints the number of records.
  210.  
  211.   4.  Calls a method that prints just the bicycles and trucks (from the sorted array using the appropriate toString() methods).
  212.  
  213.         5.  Calls a method that prints the vehicles in area code 987.
  214.  
  215. Be sure to declare variables as private, to extend all the classes appropriately, and to have the right constructors (using super where
  216. appropriate), and the getters and setters for ALL the variables. MUST SEND ALL THE OUTPUT FROM PRINTING TO THE CONSOLE, NOT TO A WINDOW.
  217.  
  218.  
  219.  
  220.  
  221. Here is my project so far:
  222.  
  223. import java.util.*;
  224. import java.io.*;
  225. import java.lang.*;
  226. public class n00640944
  227. {
  228.  
  229.   public static void main( String[] args) throws Exception
  230.   {
  231. int traceOfArray = 100;
  232. Vehicle[] vehicle = new Vehicle[traceOfArray];
  233.  
  234. File file = null;
  235. // try
  236. // {
  237. file = new File(args[0]);
  238. FileReader Fr = new FileReader(file); //read file.
  239. BufferedReader Br = new BufferedReader(Fr);
  240. String read = Br.readLine();
  241. try{
  242. while (read != null)
  243. {
  244. //System.out.println(read);
  245.  
  246.   char x = read.charAt(0);
  247. // for(int i=0; i<vehicle.length; i++)
  248. //
  249. // {
  250. if(x=='v')
  251. vehicle[0] = new Vehicle(Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine());
  252. else if(x=='c')
  253.   vehicle[1] = new Car(Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine());
  254. else
  255. break;
  256. //read = Br.readLine();
  257. }//while
  258. }//try
  259. catch(NullPointerException e){}
  260. // {
  261. // vehicle[0] = new Vehicle(Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine());
  262.  
  263. //vehicle[i++] = new VehicleArray(Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine());
  264. // }
  265. // else if(x=='c')
  266. // {
  267. // vehicle[1] = new Car(Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine());
  268. //  
  269. // }
  270. // else if(x=='a')
  271. // {
  272. // vehicle[2] = new AmericanCar(Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine(),Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine());
  273. // }
  274. // else if(x=='f')
  275. // {
  276. //   vehicle[3] = new Vehicle(Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine());  
  277. //
  278. // }
  279. // else if(x=='b')
  280. // {
  281. //                vehicle[4]=new Bicycle(Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine());
  282. //
  283. // }
  284. // else if(x=='t')
  285. // {
  286. //   vehicle[5]= new Truck(Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine(),Br.readLine(), Br.readLine(), Br.readLine());
  287. //
  288. // }
  289. // else
  290. // System.out.println("An error occured!");
  291. // }
  292. // }//end while
  293. // }//end try
  294. // catch(Exception e)//any exception
  295. // {
  296. // traceOfArray= traceOfArray*2;
  297. // Vehicle[] tempVehicle = new Vehicle[traceOfArray];
  298. // for (int i=0; i<vehicle.length; i++)
  299. // {
  300. // tempVehicle[i]= vehicle[i];
  301. // }
  302. // }
  303. }// end main
  304.  }//end class noo640944
  305.  
  306. /******************************* class vehicle*****************************/
  307. class Vehicle
  308. {
  309. private String ownerName, address, phone, email;
  310.  
  311. public Vehicle (String ownerName, String address, String phone, String email)
  312. {
  313. this.ownerName = ownerName;
  314. this.address = address;
  315. this.phone = phone;
  316. this.email = email;
  317. //System.out.println(ownerName+"\n"+ address+"\n"+ phone+"\n"+ email);
  318. }
  319. public String getName()
  320. { return ownerName; }
  321. public String getAddress()
  322. { return address;}
  323. public String getPhone()
  324. { return phone;}
  325. public String getEmail()
  326. { return email; }
  327. }//end class vehicle
  328.  
  329. /********************* class bycicle **********************/
  330. public class Bicycle extends Vehicle
  331. {
  332.   private String numOfSpeeds;
  333.  
  334. public Bicycle(String ownerName, String address, String phone, String email, String numOfSpeeds)
  335.   {
  336.   super(ownerName, address, phone, email);
  337.   this.numOfSpeeds= numOfSpeeds;
  338.   }
  339.   public String toString()
  340. {
  341.    return super.toString()
  342. }
  343. }//end class Bycicle
  344. /********************* class Truck **********************/
  345. class Truck extends Vehicle
  346. {
  347. private String numOfTons, truckCost;
  348. private String datePurchased;
  349. public Truck( String numOfTons, ,String datePurchased)//second constructor
  350. {
  351. //datePurchased = new java.util.Date();
  352. this.datePurchased= datePurchased;
  353. this.numOfTons = numOfTons;
  354. this.truckCost= truckCost;
  355. }
  356. public Truck(String ownerName, String address, String phone, String email, String numOfTons, String truckCost)
  357. {
  358. //datePurchased = new java.util.Date();
  359. super(ownerName, address, phone, email);
  360.   this.numOfTons= numOfTons;
  361. this.truckCost=truckCost;
  362. this.datePurchased= datePurchased;
  363. }
  364. public java.util.Date getDatePurchased()
  365. {
  366. return datePurchased;
  367. }
  368. }//end class Truck
  369.  
  370. /********************* class car**********************/
  371. class Car extends Vehicle
  372. {
  373.  
  374.   private String  color;
  375.   private String convertible;
  376.   public Car(String ownerName, String address, String phone, String email, String convertible, String color)
  377.   {
  378.   super(ownerName, address, phone, email);
  379. this.color = color;
  380. this.convertible = convertible;
  381.   }
  382.   public String toString()
  383. {
  384.    return super.toString();
  385.   }
  386.  
  387. }//end class Car
  388. // /********************* class americanCar**********************/
  389.  
  390. class AmericanCar extends Car
  391. {
  392.   private String madeInDetroit, unionShop;
  393.  
  394.  
  395. public AmericanCar(String ownerName,String address,String phone,String email,boolean convertible,String color,String madeInDetroit,boolean unionShop)
  396. {
  397.   super(ownerName,address,phone,email,convertible, color);
  398.   this.madeInDetroit =madeInDetroit;
  399.   this.unionShop = unionShop;
  400.   }
  401.   public String toString()
  402. {
  403.    return super.toString();
  404.   }
  405. }//end class americanCar
  406.  
  407.  
  408. /********************* class foreignCar**********************/
  409.  
  410. class ForeignCar extends Car
  411. {
  412.  
  413.   private String manufacturerCountry;
  414.   String importDuty;
  415.  
  416.  public ForeignCar(String ownerName,String address,String phone,String email,String convertible,String color,String manufacturerCountry,String importDuty)
  417.  {
  418.   super(ownerName,address,phone,email,convertible, color);
  419.   this.manufacturerCountry=manufacturerCountry;
  420.   this.importDuty=importDuty;
  421.  }//end constructor
  422.  public String toString()
  423.  {
  424.    return super.toString();
  425.  }
  426. }//end class foreignCar
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement