Advertisement
OlivsonM

OOP v4

Apr 23rd, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.14 KB | None | 0 0
  1. package com.company;
  2. import java.util.*;
  3. import java.text.*;
  4. import java.nio.file.Path;
  5. import java.nio.file.Files;
  6. import java.nio.file.Paths;
  7. import java.io.*;
  8. class Car {
  9.  
  10. private String numberPlate;
  11. public String getNumberPlate (){
  12. return this.numberPlate;
  13. }
  14. public void setNumberPlate (String numberPlate){
  15. this.numberPlate = numberPlate;
  16. }
  17. private String model;
  18. public String getModel (){
  19. return this.model;
  20. }
  21. public void setModel (String model){
  22. this.model = model;
  23. }
  24. private String colour;
  25. public String getColour (){
  26. return this.colour;
  27. }
  28. public void setColour (String colour){
  29. this.colour = colour;
  30. }
  31. private int mileage;
  32. public int getMileage (){
  33. return this.mileage;
  34. }
  35. public void setMileage (String mileage){
  36. this.mileage = Integer.parseInt(mileage);
  37. }
  38. private String accidentHistory;
  39. public String getAccidentHistory(){
  40. return this.accidentHistory;
  41. }
  42. public void setAccidentHistory (String accidentHistory){
  43. this.accidentHistory = accidentHistory;
  44. }
  45. private int price;
  46. public int getPrice (){
  47. return this.price;
  48. }
  49. public void setprice(String price){
  50. this.price = Integer.parseInt(price);
  51. }
  52. private Date arrivalDate;
  53. public Date getArrivalDate (){
  54. return this.arrivalDate;
  55. }
  56. public void setArrivalDate (String arrivalDate) {
  57. SimpleDateFormat dateType = new SimpleDateFormat("yyyy-mm-dd");
  58. try {
  59. this.arrivalDate = dateType.parse(arrivalDate);
  60. } catch (ParseException e) {
  61. System.out.println("wrong date");
  62. }
  63. }
  64.  
  65. private Date sellingDate;
  66. public Date getSellingDate (){
  67. return this.sellingDate;
  68. }
  69. public void setSellingDate (String sellingDate){
  70. SimpleDateFormat dateType = new SimpleDateFormat("yyyy-mm-dd");
  71. try {
  72. this.sellingDate = dateType.parse(sellingDate);
  73. }
  74. catch (ParseException e){
  75. System.out.println("wrong date");
  76. }
  77. }
  78. public void setSellingDate (Date sellingDate){
  79. this.sellingDate = sellingDate;
  80. }
  81. private CarType carType;
  82. public CarType getCarType (){
  83. return this.carType;
  84. }
  85. public void setCarType (String carType) {
  86. if (carType == "Hatchback") {
  87. this.carType = CarType.Hatchback;
  88. } else if (true) {
  89. }
  90. }
  91. private Size size;
  92. public Size getSize (){
  93. return this.size;
  94. }
  95. public void setSize (String size){
  96. if (size == "large") {
  97. this.size = Size.Large;
  98. }
  99. else if (size == "small"){
  100. this.size = Size.Small;
  101. }
  102. }
  103. private Transmission transmission;
  104. public Transmission getTransmission (){
  105. return this.transmission;
  106. }
  107. public void setTransmission (String transmission){
  108. this.transmission = transmission;
  109. }
  110. Car(){
  111. numberPlate = "";
  112. model = "";
  113. colour = "";
  114. mileage = 0;
  115. accidentHistory = "";
  116. price = 0;
  117. arrivalDate = new Date ();
  118. sellingDate = new Date ();
  119. carType = CarType.Saloon;
  120. size = Size.Large;
  121. transmission = Transmission.Automatic;
  122. }
  123. Car (String numberPlate, String model, String colour, int mileage, String accidentHistory, int price, String arrivalDate, String sellingDate, CarType carType, Size size, Transmission transmission){
  124. this.numberPlate = numberPlate;
  125. this.model = model;
  126. this.colour = colour;
  127. this.mileage = mileage;
  128. this.accidentHistory = accidentHistory;
  129. this.price = price;
  130. SimpleDateFormat dateType = new SimpleDateFormat("yyyy-mm-dd");
  131. try {
  132. this.arrivalDate = dateType.parse(arrivalDate);
  133. this.sellingDate = dateType.parse(sellingDate);
  134. }
  135. catch (ParseException e){
  136. System.out.println("wrong date");
  137. }
  138. this.carType = carType;
  139. this.size = size;
  140. this.transmission = transmission;
  141. }
  142. }
  143. enum CarType {
  144. Hatchback (5,4), Saloon (5,5), SUV(5,5), MPV(5,7), Van(5,3), Coupe(2,2);
  145. private int doors;
  146. private int seats;
  147. CarType (int doors, int seats){
  148. this.doors = doors;
  149. this.seats = seats;
  150. }
  151. public int getSeats() {
  152. return seats;
  153. }
  154. public int getDoors() {
  155. return doors;
  156. }
  157. }
  158. enum Size {
  159. Large("Large"), Small("Small");
  160. private String size;
  161. Size (String size){
  162. this.size = size;
  163. }
  164. public String GetSize (){
  165. return this.size;
  166. }
  167. public void SetSize (String size){
  168. this.size = size;
  169. }
  170. }
  171. enum Transmission {
  172. Automatic("Automatic"), Manual("Manual");
  173. private String transmission;
  174. Transmission(String transmission){
  175. this.transmission = transmission;
  176. }
  177.  
  178. }
  179. class Person {
  180. protected String username, password;
  181. }
  182. class Staff extends Person {
  183. public void AddCars(ArrayList<Car>cars){
  184.  
  185. try {
  186. FileReader file = new FileReader("ArrayList.txt");
  187.  
  188. BufferedReader reader = new BufferedReader(file);
  189. String line;
  190. String [] arrayLine;
  191.  
  192. while ((line = reader.readLine()) != null) {
  193. arrayLine = line.split(", ");
  194. Car car = new Car();
  195. car.setNumberPlate(arrayLine[0]);
  196. car.setModel(arrayLine [1]);
  197. car.setCarType(arrayLine [2]);
  198. int x = 1;
  199. if (arrayLine[2]== "Van"){
  200. x = 0;
  201. car.setSize(arrayLine[3]);
  202. }
  203. car.setColour(arrayLine[4-x]);
  204. car.setMileage(arrayLine[5-x]);
  205. car.setAccidentHistory(arrayLine[6-x]);
  206. car.setTransmission(arrayLine[7-x]);
  207. car.setprice(arrayLine[8-x]);
  208. if (9-x<arrayLine.length){
  209. car.setArrivalDate(arrayLine[9-x]);
  210. }
  211. if (10-x<arrayLine.length){
  212. car.setSellingDate(arrayLine[10-x]);
  213. }
  214. cars.add(car);
  215. }
  216. } catch (IOException e) {
  217. System.out.println("failure");
  218. }
  219. }
  220. public void AddCar(Car car){
  221.  
  222.  
  223. }
  224. public void SellCar(Car car, ArrayList <Car>cars){
  225. for (Car temporaryCar:cars){
  226. if(car.getNumberPlate()== temporaryCar.getNumberPlate()){
  227. temporaryCar.setSellingDate(new Date());
  228. break;
  229. }
  230. }
  231.  
  232. }
  233. public void PrintCars(){
  234.  
  235. }
  236. public ArrayList<Car> Search(String colour, ArrayList<Car>cars){
  237. ArrayList <Car>selectedCars = new ArrayList<>();
  238. for (Car temporaryCar:cars){
  239. if (temporaryCar.getColour() == colour){
  240. selectedCars.add(temporaryCar);
  241. }
  242. }
  243. return selectedCars;
  244. }
  245. public ArrayList<Car> Search(String model, Transmission transmission, ArrayList<Car>cars){
  246. ArrayList <Car>selectedCars = new ArrayList<>();
  247. for (Car temporaryCar:cars){
  248. if (temporaryCar.getModel() == model && temporaryCar.getTransmission() == transmission){
  249. selectedCars.add(temporaryCar);
  250. }
  251. }
  252. return selectedCars;
  253. }
  254. public ArrayList<Car> Search(int min, int max, ArrayList<Car>cars){
  255. ArrayList <Car>selectedCars = new ArrayList<>();
  256. for (Car temporaryCar:cars){
  257. if (temporaryCar.getCarType().getSeats() >= min && temporaryCar.getCarType().getSeats()<= max){
  258. selectedCars.add(temporaryCar);
  259. }
  260. }
  261. return selectedCars;
  262.  
  263. }
  264. public ArrayList<Car> Search(Size size,ArrayList<Car>cars){
  265. ArrayList <Car>selectedCars = new ArrayList<>();
  266. for (Car temporaryCar:cars){
  267. if (temporaryCar.getCarType()== CarType.Van && temporaryCar.getSize()== size){
  268. selectedCars.add(temporaryCar);
  269. }
  270. }
  271. return selectedCars;
  272.  
  273. }
  274. public int CalculateRevenue(ArrayList <Car>cars,Date sellingDate){
  275. int result = 0;
  276. for (int i=0; i<cars.size();i++){
  277. if (cars.get(i).getSellingDate()== sellingDate){
  278. result += cars.get(i).getPrice();
  279. }
  280. }
  281. return result;
  282. }
  283. /*public int CalculateRevenue(ArrayList <Car>cars,Date sellingDate){
  284. int result = 0;
  285. for (int i=0; i<cars.size();i++){
  286. if (cars.get(i).getSellingDate()== sellingDate){
  287. result += cars.get(i).getPrice();
  288. }
  289. }
  290. return result;
  291. }*/
  292.  
  293. }
  294. class Customer extends Person {
  295.  
  296. }
  297. class Admin extends Staff {
  298.  
  299. }
  300. public class Main {
  301.  
  302. public static void main(String[] args) {
  303. ArrayList <Car>cars = new ArrayList<Car>();
  304. Staff Jon = new Staff();
  305. Jon.AddCars(cars);
  306.  
  307. }
  308. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement