Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.*;
- import java.text.*;
- import java.nio.file.Path;
- import java.nio.file.Files;
- import java.nio.file.Paths;
- import java.io.*;
- class Car {
- private String numberPlate;
- public String getNumberPlate (){
- return this.numberPlate;
- }
- public void setNumberPlate (String numberPlate){
- this.numberPlate = numberPlate;
- }
- private String model;
- public String getModel (){
- return this.model;
- }
- public void setModel (String model){
- this.model = model;
- }
- private String colour;
- public String getColour (){
- return this.colour;
- }
- public void setColour (String colour){
- this.colour = colour;
- }
- private int mileage;
- public int getMileage (){
- return this.mileage;
- }
- public void setMileage (String mileage){
- this.mileage = Integer.parseInt(mileage);
- }
- private String accidentHistory;
- public String getAccidentHistory(){
- return this.accidentHistory;
- }
- public void setAccidentHistory (String accidentHistory){
- this.accidentHistory = accidentHistory;
- }
- private int price;
- public int getPrice (){
- return this.price;
- }
- public void setprice(String price){
- this.price = Integer.parseInt(price);
- }
- private Date arrivalDate;
- public Date getArrivalDate (){
- return this.arrivalDate;
- }
- public void setArrivalDate (String arrivalDate) {
- SimpleDateFormat dateType = new SimpleDateFormat("yyyy-mm-dd");
- try {
- this.arrivalDate = dateType.parse(arrivalDate);
- } catch (ParseException e) {
- System.out.println("wrong date");
- }
- }
- private Date sellingDate;
- public Date getSellingDate (){
- return this.sellingDate;
- }
- public void setSellingDate (String sellingDate){
- SimpleDateFormat dateType = new SimpleDateFormat("yyyy-mm-dd");
- try {
- this.sellingDate = dateType.parse(sellingDate);
- }
- catch (ParseException e){
- System.out.println("wrong date");
- }
- }
- public void setSellingDate (Date sellingDate){
- this.sellingDate = sellingDate;
- }
- private CarType carType;
- public CarType getCarType (){
- return this.carType;
- }
- public void setCarType (String carType) {
- if (carType == "Hatchback") {
- this.carType = CarType.Hatchback;
- } else if (true) {
- }
- }
- private Size size;
- public Size getSize (){
- return this.size;
- }
- public void setSize (String size){
- if (size == "large") {
- this.size = Size.Large;
- }
- else if (size == "small"){
- this.size = Size.Small;
- }
- }
- private Transmission transmission;
- public Transmission getTransmission (){
- return this.transmission;
- }
- public void setTransmission (String transmission){
- this.transmission = transmission;
- }
- Car(){
- numberPlate = "";
- model = "";
- colour = "";
- mileage = 0;
- accidentHistory = "";
- price = 0;
- arrivalDate = new Date ();
- sellingDate = new Date ();
- carType = CarType.Saloon;
- size = Size.Large;
- transmission = Transmission.Automatic;
- }
- Car (String numberPlate, String model, String colour, int mileage, String accidentHistory, int price, String arrivalDate, String sellingDate, CarType carType, Size size, Transmission transmission){
- this.numberPlate = numberPlate;
- this.model = model;
- this.colour = colour;
- this.mileage = mileage;
- this.accidentHistory = accidentHistory;
- this.price = price;
- SimpleDateFormat dateType = new SimpleDateFormat("yyyy-mm-dd");
- try {
- this.arrivalDate = dateType.parse(arrivalDate);
- this.sellingDate = dateType.parse(sellingDate);
- }
- catch (ParseException e){
- System.out.println("wrong date");
- }
- this.carType = carType;
- this.size = size;
- this.transmission = transmission;
- }
- }
- enum CarType {
- Hatchback (5,4), Saloon (5,5), SUV(5,5), MPV(5,7), Van(5,3), Coupe(2,2);
- private int doors;
- private int seats;
- CarType (int doors, int seats){
- this.doors = doors;
- this.seats = seats;
- }
- public int getSeats() {
- return seats;
- }
- public int getDoors() {
- return doors;
- }
- }
- enum Size {
- Large("Large"), Small("Small");
- private String size;
- Size (String size){
- this.size = size;
- }
- public String GetSize (){
- return this.size;
- }
- public void SetSize (String size){
- this.size = size;
- }
- }
- enum Transmission {
- Automatic("Automatic"), Manual("Manual");
- private String transmission;
- Transmission(String transmission){
- this.transmission = transmission;
- }
- }
- class Person {
- protected String username, password;
- }
- class Staff extends Person {
- public void AddCars(ArrayList<Car>cars){
- try {
- FileReader file = new FileReader("ArrayList.txt");
- BufferedReader reader = new BufferedReader(file);
- String line;
- String [] arrayLine;
- while ((line = reader.readLine()) != null) {
- arrayLine = line.split(", ");
- Car car = new Car();
- car.setNumberPlate(arrayLine[0]);
- car.setModel(arrayLine [1]);
- car.setCarType(arrayLine [2]);
- int x = 1;
- if (arrayLine[2]== "Van"){
- x = 0;
- car.setSize(arrayLine[3]);
- }
- car.setColour(arrayLine[4-x]);
- car.setMileage(arrayLine[5-x]);
- car.setAccidentHistory(arrayLine[6-x]);
- car.setTransmission(arrayLine[7-x]);
- car.setprice(arrayLine[8-x]);
- if (9-x<arrayLine.length){
- car.setArrivalDate(arrayLine[9-x]);
- }
- if (10-x<arrayLine.length){
- car.setSellingDate(arrayLine[10-x]);
- }
- cars.add(car);
- }
- } catch (IOException e) {
- System.out.println("failure");
- }
- }
- public void AddCar(Car car){
- }
- public void SellCar(Car car, ArrayList <Car>cars){
- for (Car temporaryCar:cars){
- if(car.getNumberPlate()== temporaryCar.getNumberPlate()){
- temporaryCar.setSellingDate(new Date());
- break;
- }
- }
- }
- public void PrintCars(){
- }
- public ArrayList<Car> Search(String colour, ArrayList<Car>cars){
- ArrayList <Car>selectedCars = new ArrayList<>();
- for (Car temporaryCar:cars){
- if (temporaryCar.getColour() == colour){
- selectedCars.add(temporaryCar);
- }
- }
- return selectedCars;
- }
- public ArrayList<Car> Search(String model, Transmission transmission, ArrayList<Car>cars){
- ArrayList <Car>selectedCars = new ArrayList<>();
- for (Car temporaryCar:cars){
- if (temporaryCar.getModel() == model && temporaryCar.getTransmission() == transmission){
- selectedCars.add(temporaryCar);
- }
- }
- return selectedCars;
- }
- public ArrayList<Car> Search(int min, int max, ArrayList<Car>cars){
- ArrayList <Car>selectedCars = new ArrayList<>();
- for (Car temporaryCar:cars){
- if (temporaryCar.getCarType().getSeats() >= min && temporaryCar.getCarType().getSeats()<= max){
- selectedCars.add(temporaryCar);
- }
- }
- return selectedCars;
- }
- public ArrayList<Car> Search(Size size,ArrayList<Car>cars){
- ArrayList <Car>selectedCars = new ArrayList<>();
- for (Car temporaryCar:cars){
- if (temporaryCar.getCarType()== CarType.Van && temporaryCar.getSize()== size){
- selectedCars.add(temporaryCar);
- }
- }
- return selectedCars;
- }
- public int CalculateRevenue(ArrayList <Car>cars,Date sellingDate){
- int result = 0;
- for (int i=0; i<cars.size();i++){
- if (cars.get(i).getSellingDate()== sellingDate){
- result += cars.get(i).getPrice();
- }
- }
- return result;
- }
- /*public int CalculateRevenue(ArrayList <Car>cars,Date sellingDate){
- int result = 0;
- for (int i=0; i<cars.size();i++){
- if (cars.get(i).getSellingDate()== sellingDate){
- result += cars.get(i).getPrice();
- }
- }
- return result;
- }*/
- }
- class Customer extends Person {
- }
- class Admin extends Staff {
- }
- public class Main {
- public static void main(String[] args) {
- ArrayList <Car>cars = new ArrayList<Car>();
- Staff Jon = new Staff();
- Jon.AddCars(cars);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement