Advertisement
OlivsonM

OOP Car dealership

Apr 22nd, 2019
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.78 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. public String model;
  18. public String getModel (){
  19. return this.model;
  20. }
  21. public void setModel (String model){
  22. this.model = model;
  23. }
  24. public String colour;
  25. public String getColour (){
  26. return this.colour;
  27. }
  28. public void setColour (String colour){
  29. this.colour = colour;
  30. }
  31. public int mileage;
  32. public int getMileage (){
  33. return this.mileage;
  34. }
  35. public void setMileage (int mileage){
  36. this.mileage = mileage;
  37. }
  38. public String accidentHistory;
  39. public String getAccidentHistory(){
  40. return this.accidentHistory;
  41. }
  42. public void setAccidentHistory (String accidentHistory){
  43. this.accidentHistory = accidentHistory;
  44. }
  45. public int price;
  46. public int getPrice (){
  47. return this.price;
  48. }
  49. public void setprice(int price{
  50. this.price = price;
  51. }
  52. public Date arrivalDate;
  53. public Date getArrivalDate (){
  54. return this.arrivalDate;
  55. }
  56. public void setArrivalDate (Date arrivalDate){
  57. this.arrivalDate = arrivalDate;
  58. }
  59. private Date sellingDate;
  60. public Date getSellingDate (){
  61. return this.sellingDate;
  62. }
  63. public void setSellingDate (Date sellingDate){
  64. this.sellingDate = sellingDate;
  65. }
  66. public CarType carType;
  67. public CarType getCarType (){
  68. return this.carType;
  69. }
  70. public void setCarType (CarType carType){
  71. this.carType = carType;
  72. }
  73. public Size size;
  74. public Size getSize (){
  75. return this.size;
  76. }
  77. public void setSize (Size size){
  78. this.size = size;
  79. }
  80. public Transmission transmission;
  81. public Transmission getTransmission (){
  82. return this.transmission;
  83. }
  84. public void setTransmission (Transmission transmission){
  85. this.transmission = transmission;
  86. }
  87. Car(){
  88. numberPlate = "";
  89. model = "";
  90. colour = "";
  91. mileage = 0;
  92. accidentHistory = "";
  93. price = 0;
  94. arrivalDate = new Date ();
  95. sellingDate = new Date ();
  96. carType = CarType.Saloon;
  97. size = Size.Large;
  98. transmission = Transmission.Automatic;
  99. }
  100. Car (String numberPlate, String model, String colour, int mileage, String accidentHistory, int price, String arrivalDate, String sellingDate, CarType carType, Size size, Transmission transmission){
  101. this.numberPlate = numberPlate;
  102. this.model = model;
  103. this.colour = colour;
  104. this.mileage = mileage;
  105. this.accidentHistory = accidentHistory;
  106. this.price = price;
  107. SimpleDateFormat dateType = new SimpleDateFormat("yyyy-mm-dd");
  108. try {
  109. this.arrivalDate = dateType.parse(arrivalDate);
  110. this.sellingDate = dateType.parse(sellingDate);
  111. }
  112. catch (ParseException e){
  113. System.out.println("wrong date");
  114. }
  115. this.carType = carType;
  116. this.size = size;
  117. this.transmission = transmission;
  118. }
  119. }
  120. enum CarType {
  121. Hatchback (5,4), Saloon(5,5), SUV(5,5), MPV(5,7), Van(5,3), Coupe(2,2);
  122. private int doors;
  123. private int seats;
  124. CarType (int doors, int seats){
  125. this.doors = doors;
  126. this.seats = seats;
  127. }
  128. }
  129. enum Size {
  130. Large("Large"), Small("Small");
  131. private String size;
  132. Size (String size){
  133. this.size = size;
  134. }
  135. public String GetSize (){
  136. return this.size;
  137. }
  138. public void SetSize (String size){
  139. this.size = size;
  140. }
  141. }
  142. enum Transmission {
  143. Automatic("Automatic"), Manual("Manual");
  144. private String transmission;
  145. Transmission(String transmission){
  146. this.transmission = transmission;
  147. }
  148.  
  149. }
  150. class Person {
  151. protected String username, password;
  152. }
  153. class Staff extends Person {
  154. public void AddCars(ArrayList<Car>cars){
  155. String filename = "Preboot:\\Users\\maximolivson\\IdeaProjects\\untitled\\src\\com\\company\\maximolivson\\IdeaProjects\\ArrayList.txt";
  156. String output = "";
  157. try{
  158. output = Files.lines (Paths.get(filename)).reduce("",(a,b)->a+"\n"+b);
  159. }
  160. catch (IOException fail){
  161. System.out.println(fail.getMessage());
  162. }
  163. System.out.println(output);
  164.  
  165.  
  166.  
  167. }
  168. public void AddCar(Car car){
  169.  
  170.  
  171. }
  172. public void SellCar(Car car, ArrayList <Car>cars){
  173. for (Car temporaryCar:cars){
  174. if(car.getNumberPlate()== temporaryCar.getNumberPlate()){
  175. temporaryCar.setSellingDate(new Date());
  176. break;
  177. }
  178. }
  179.  
  180. }
  181. public void PrintCars(){
  182.  
  183. }
  184. public void Search2(Car car){
  185.  
  186.  
  187. }
  188. public void Search(String model, Transmission transmission, ArrayList<Car>cars){
  189. ArrayList <Car>selectedCars = new ArrayList<Car>();
  190. for (Car temporaryCar:cars){
  191. if (car.getModel() == model && car.getTransmission() == transmission){
  192. selectedCars.add(temporaryCar);
  193. }
  194. }
  195.  
  196.  
  197. }
  198. public void Search3(Car car){
  199.  
  200. }
  201. public void CalculateRevenue(Car car){
  202.  
  203. }
  204.  
  205. }
  206. class Customer extends Person {
  207.  
  208. }
  209. class Admin extends Staff {
  210.  
  211. }
  212. public class Main {
  213.  
  214. public static void main(String[] args) {
  215. ArrayList <Car>cars = new ArrayList<Car>();
  216. Staff Jon = new Staff();
  217. Jon.AddCars(cars);
  218.  
  219. }
  220. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement