Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please i want this answer for java j2sdk1.4.1 it is a project for university so

ID: 3622927 • Letter: P

Question

please i want this answer for java j2sdk1.4.1 it is a project for university so please make sure it is for java j2sdk1.4.1 thank you in advance and in university we use the SavitchIn


Design and implement the following two classes:
1. A class personType contains the following protected data members:
a. Person firstName
b. Person lastName
personType class contains the following methods: constructors, set, get and print

2. A class customerType contains the following private data members:
a. studentId
b. list for cars rented (array of strings)
c. maxsize of the list of cars (default equal 10)
d. ncars of cars rented
customerType class contains the following methods:
• Constructor
• set (to set the student firstName, lastName, customerId, and cars rented)
• return a car
• print ( to output the customer name, customerId, and cars rented)
• writeToFile(to print the id’s and names of the customers to a file)

Notice that customerType calss inherits the name of the personType calss and that the set and print methods of customerType class will have to call the set and the print of the personType class.

3. A class carType that keeps records of the available and rented cars, it has:
a. carId
b. carType
c. status(available/not available)
CarType class contains the following methods:
a. constructor
b. setInfo
c. getId, getType, getStatus
d. rentCar
e. returnCar

Write a main Method to declare a dynamic array of customerType objects and a dynamic array of carType objects and then display a menu to the user to choose any possible operation for as many times as he/she wants.

Explanation / Answer

import java.util.*;

public class Main {

    public void mainApplication()
    {
        Scanner sin = new Scanner(System.in);
        Scanner sin1 = new Scanner(System.in);
        Scanner sin2 = new Scanner(System.in);
        int carId = 0;
        String carName = null;
        int choice=0;
        List<carType> cars=new ArrayList<carType>();

        List<customerType> customers=new ArrayList<customerType>();
        while(true)
        {

            System.out.println("1.Add Car");
            System.out.println("2.Add Customer");
            System.out.println("3.Display Customer details");
            System.out.println("4.Rent car to customer");
            System.out.println("5.Display All cars");
            System.out.println("6.Display All customers");
            System.out.println("Please enter your choice:");
            try
            {
                choice=sin.nextInt();
            }
            catch(Exception ex)
            {
                System.out.println("Invalid data");
            }
            switch(choice)
            {
                case 1:
                       System.out.println("Enter car ID");
                       carId=sin1.nextInt();
                       System.out.println("Enter car Name");
                       carName=sin2.nextLine();
                       carType car = new carType(carId, carName, "Y");
                       cars.add(car);
                       break;
                case 2:
                       System.out.println("Enter Customer ID:");
                       int custId=sin1.nextInt();
                       System.out.println("Enter Customer First Name:");
                       String FName=sin2.nextLine();
                       System.out.println("Enter Customer Last Name:");
                       String LName=sin2.nextLine();
                       System.out.println("Max number of cars:");
                       int maxNumber=sin1.nextInt();
                       customers.add(new customerType(custId, maxNumber, FName, LName));
                       break;
                case 3:
                        System.out.println("Enter Customer ID:");
                        int Id=sin1.nextInt();
                        for(int i=0;i<customers.size();i++)
                        {
                            if(customers.get(i).getStudentId()==Id)
                                customers.get(i).printData();
                        }
                       
                        break;
                case 4:
                      System.out.println("Enter Customer ID:");
                      int cusId=sin1.nextInt();
                      int statusCheck=0;
                      System.out.println("Enter car ID");
                      carId=sin1.nextInt();
                      for(int i=0;i<customers.size();i++)
                      {
                        if(cusId==customers.get(i).getStudentId())
                        {
                            for(int j=0;i<cars.size();j++)
                            {
                                if(cars.get(j).getCarId()==carId)
                                {
                                    customers.get(i).setCarsRented(cars.get(j).getCarType());
                                    statusCheck=1;
                                    break;
                                }
                            }

                        }
                      }
                      if(statusCheck==1)
                      {
                          System.out.println("Succes fully rented");
                      }
                      else
                      {
                          System.out.println("Invalid data");
                      }
                      break;
                case 5:
                        System.out.println("Car Id"+ "   "+"Car Name");
                       for(int i=0;i<cars.size();i++)
                       {
                          
                           System.out.println(cars.get(i).getCarId()+" "+cars.get(i).getCarType());
                       }
                       break;
                case 6:
                        for(int i=0;i<customers.size();i++)
                        {
                            customers.get(i).printData();
                        }
                        break;
               
               
               
            }

        }

    }
    public static void main(String[] args) {
        Main main=new Main();
        main.mainApplication();

    }
    public class customerType extends personType
    {
        private int studentId;
        private List<String> carsRented=new ArrayList<String>();
        private int MaxCars=10;
        private int totalCarsRented=0;
       
        public customerType(int studentId,int MaxCars,String fname,String lname)
        {
            super(fname,lname);
            this.studentId=studentId;
            this.MaxCars=MaxCars;
        }
        public void printData()
        {
            print();
            System.out.println("Customer ID:"+studentId);
            System.out.println("Cars rented:");
            for(int i=0;i<carsRented.size();i++)
            {
                System.out.println(carsRented.get(i)+",");
            }
        }
        /**
         * @return the studentId
         */
        public int getStudentId() {
            return studentId;
        }

        /**
         * @param studentId the studentId to set
         */
        public void setStudentId(int studentId) {
            this.studentId = studentId;
        }

        /**
         * @return the carsRented
         */
        public List<String> getCarsRented() {
            return carsRented;
        }

        /**
         * @param carsRented the carsRented to set
         */
        public void setCarsRented(String car) {
            carsRented.add(car);
        }

        /**
         * @return the MaxCars
         */
        public int getMaxCars() {
            return MaxCars;
        }

        /**
         * @param MaxCars the MaxCars to set
         */
        public void setMaxCars(int MaxCars) {
            this.MaxCars = MaxCars;
        }

        /**
         * @return the totalCarsRented
         */
        public int getTotalCarsRented() {
            return totalCarsRented;
        }

        /**
         * @param totalCarsRented the totalCarsRented to set
         */
        public void setTotalCarsRented(int totalCarsRented) {
            this.totalCarsRented = totalCarsRented;
        }
    }
    private class carType
    {
        private int carId;
        private String carType;
        private String status;

        public carType()
        {
           
        }
        public carType(int carId,String carType,String status)
        {
            this.carId=carId;
            this.carType=carType;
            this.status=status;
        }
        public void rentCar()
        {
            status="N";
        }
        public carType returnCar()
        {
            return new carType(carId,carType,status);
        }
        /**
         * @return the carId
         */
        public int getCarId() {
            return carId;
        }

        /**
         * @param carId the carId to set
         */
        public void setCarId(int carId) {
            this.carId = carId;
        }

        /**
         * @return the carType
         */
        public String getCarType() {
            return carType;
        }

        /**
         * @param carType the carType to set
         */
        public void setCarType(String carType) {
            this.carType = carType;
        }

        /**
         * @return the status
         */
        public String getStatus() {
            return status;
        }

        /**
         * @param status the status to set
         */
        public void setStatus(String status) {
            this.status = status;
        }

    }
    public class personType {

        private String firstName;
        private String lastName;

        public personType()
        {

        }
        public personType(String fname,String lname)
        {
            firstName=fname;
            lastName=lname;
        }
        public void print()
        {
            System.out.println("First Name:"+firstName);
            System.out.println("Last Name:"+lastName);
        }
        /**
         * @return the firstName
         */
        public String getFirstName() {
            return firstName;
        }

        /**
         * @param firstName the firstName to set
         */
        public void setFirstName(String firstName) {
            this.firstName = firstName;
        }

        /**
         * @return the lastName
         */
        public String getLastName() {
            return lastName;
        }

        /**
         * @param lastName the lastName to set
         */
        public void setLastName(String lastName) {
            this.lastName = lastName;
        }
    }
}

------------------------------------------------------------------------------

Save the aboue file as Main.java

Samle execution:

run:
1.Add Car
2.Add Customer
3.Display Customer details
4.Rent car to customer
5.Display All cars
6.Display All customers
Please enter your choice:
1
Enter car ID
12
Enter car Name
abc
1.Add Car
2.Add Customer
3.Display Customer details
4.Rent car to customer
5.Display All cars
6.Display All customers
Please enter your choice:
2
Enter Customer ID:
50
Enter Customer First Name:
ash
Enter Customer Last Name:
ok
Max number of cars:
3
1.Add Car
2.Add Customer
3.Display Customer details
4.Rent car to customer
5.Display All cars
6.Display All customers
Please enter your choice:
3
Enter Customer ID:
50
First Name:ash
Last Name:ok
Customer ID:50
Cars rented:
1.Add Car
2.Add Customer
3.Display Customer details
4.Rent car to customer
5.Display All cars
6.Display All customers
Please enter your choice:
4
Enter Customer ID:
50
Enter car ID
12
Succes fully rented
1.Add Car
2.Add Customer
3.Display Customer details
4.Rent car to customer
5.Display All cars
6.Display All customers
Please enter your choice:
3
Enter Customer ID:
50
First Name:ash
Last Name:ok
Customer ID:50
Cars rented:
abc,
1.Add Car
2.Add Customer
3.Display Customer details
4.Rent car to customer
5.Display All cars
6.Display All customers
Please enter your choice:
5
Car Id   Car Name
12 abc
1.Add Car
2.Add Customer
3.Display Customer details
4.Rent car to customer
5.Display All cars
6.Display All customers
Please enter your choice:
6
First Name:ash
Last Name:ok
Customer ID:50
Cars rented:
abc,
1.Add Car
2.Add Customer
3.Display Customer details
4.Rent car to customer
5.Display All cars
6.Display All customers
Please enter your choice: