please need help with the java program
A micro car rental company.
package yourLastName.cis4110.assignment5;
Please create an enum type, say Cartype, featuring all rental car types -- SUBCOMPACT, COMPACT, MIDSIZE, FULLSIZE
(You may put the enum definition in Car class)
class Car
Instance variables:
- private String plateNum
- private Cartype carType
- private boolean availability
Member methods:
- Please define all setters and getters
class RentACar - This is a five car system for prototyping
instance variables:
- Car rentalCars[5] //a constant size so that you don't have to worry about handling the flexible size of the array.
member methods:
- public void setRentalCars(Car[] rentalcars) // array as a formal param
- public Car[] getRentalCars() //array as a return type; pay attention to deep copy
- public String rentACar(cartype) // eg. rentACar(Car.cartype.COMPACT);
return plateNum if available, otherwise null or empty string "" //search through the rental car list and find the first available car of the type matching the argument; //Please note, once the car is rented, the car's availability should be set to false or 0.
-returnACar(platNum) //Reset the car's availability to true
classManageCars// or any name if you'd like. Put your main() function here to test your program.
In your main()
1). You may manually create five Car objects here, say Car[] myRentalCars = new Car[5]. No need to use Scanner to ask user to input data to save time. e.g.: You may directly put - rentalCar[0] = new Car(); rentalCar[0].setPlateNum("P1"); rentalCar[0].setCarSize(Car.rentalcar.COMPACT); rentalCar[0].setAvailability(true); or using a Car constructor of three parameters e.g.: new Car("P1", Car.rentalcar.COMPACT,1);
2). Create a CarRental object, say myRental
3) myRental.setRentalCars(myRentalCars);
4) Put a few calls to rentACar() and returnACar() of myRental to test your program. e.g.: myRental.rentACar(Car.cartype.COMPACT); myRental.rentACar(Car.cartype.MIDSIZE); myRental.returnACar("PlateNo1");
To add any additional properties, methods if necessary
The source code for the same is as follows:
Source Code:
package yourLastName.cis4110.assignment5;
class Car {
enum Cartype {
SUBCOMPACT, COMPACT, MIDSIZE, FULLSIZE
};
private String plateNum;
private Cartype carType;
private boolean availability;
public Car() {
}
public Car(String plateNum, Cartype
carType, boolean availability) {
this.plateNum = plateNum;
this.carType = carType;
this.availability = availability;
}
public String getPlateNum() {
return plateNum;
}
public void setPlateNum(String
plateNum) {
this.plateNum = plateNum;
}
public Cartype getCarType() {
return carType;
}
public void setCarType(Cartype
carType) {
this.carType = carType;
}
public boolean getAvailability()
{
return availability;
}
public void setAvailability(boolean
availability) {
this.availability = availability;
}
}
class RentACar {
private Car rentalCar[] = new Car[5];
public void setRentalCars(Car[]
rentalcars) {
for (int i = 0; i < 5; i++) {
rentalCar[i] = rentalcars[i];
}
}
public Car[] getRentalCars() {
Car cars[] = new Car[5];
for (int i = 0; i < 5; i++)
{
cars[i] = rentalCar[i];
}
return cars;
}
public String rentACar(Car.Cartype
c) {
for (int i = 0; i < 5; i++) {
if (rentalCar[i].getCarType() == c) {
rentalCar[i].setAvailability(false);
return rentalCar[i].getPlateNum();
}
}
return "";
}
public void returnACar(String
platNum) {
for (int i = 0; i < 5; i++) {
if (rentalCar[i].getPlateNum().equals(platNum)) {
rentalCar[i].setAvailability(true);
break;
}
}
}
}
class ManageCars {
public static void main(String[]
args) {
Car[] myRentalCars = new Car[5];
myRentalCars[0] = new Car();
myRentalCars[0].setPlateNum("P1");
myRentalCars[0].setCarType(Car.Cartype.COMPACT);
myRentalCars[0].setAvailability(true);
myRentalCars[1] = new Car("P2",
Car.Cartype.SUBCOMPACT, true);
myRentalCars[2] = new Car("P3", Car.Cartype.FULLSIZE, true);
myRentalCars[3] = new Car("P4", Car.Cartype.MIDSIZE, true);
myRentalCars[4] = new Car("P5", Car.Cartype.SUBCOMPACT, true);
RentACar myRental = new RentACar();
myRental.setRentalCars(myRentalCars);
System.out.println("Car of type
COMPACT rented having plate number: " +
myRental.rentACar(Car.Cartype.COMPACT));
System.out.println("Car of type MIDSIZE rented having plate number:
" + myRental.rentACar(Car.Cartype.MIDSIZE));
System.out.println("Returning a car
with plate number P1");
myRental.returnACar("P1");
}
}
Output:

Description:
Here I have written the 3 classes as needed.
At first, I am creating enum Cartype with 4 values.
Car class has 3 member variables and I have written a constructor for this, it was mentioned at the end that you can use the constructor so I defined it here.
Then I have created the getter and setter methods for every variable.
The next class is RentACar.
In this, I am defining an array of 5 Car object.
for setting and getting the array elements, deep copy is to be used.
This means you should copy each and every element of array from source to destination instead of just writing cars = rentalCar or rentalCar = cars.
If you write as above, it is shallow copying in which rentalCar and cars, both the object are pointing to the same location. But we need to make 2 arrays so both of the arrays must be different. So I have used a for loop which runs for 5 times, (number of car object times) and copying each and every array element i.e. object in setter and getter method.
In the rentACar(), a car type from above 4 is specified and if that type car is available, it is returned and its availability is set to false.
As it is asked that the first available car of that type is to be returned, I am using the for loop and iterating through every element, and when the first element of that car type is found, its availability is set to false and then the car object is returned.
If there is no such car object with that type, "" is returned.
The last method returnACar() is taking a plate number and then finding the car with that number plate and then sets its availability to true as this means this car was given for rent and now it is returned.
In the ManageCars class, I am writing a main() method in which I am creating a 5 Car object array and setting the values.
Then I am renting two cars, one with type COMPACT and the other with MIDSIZE.
So, for size COMPACT, car with number plate P1 is given for rent and for size MIDSIZE, car with number plate P4 is given for rent.
And then I am returning a car with number plate P1.
Do comment if there is any query. Thank you. :)
please need help with the java program A micro car rental company. package yourLastName.cis4110.assignment5; Please create...
Please help me do these two programs in JAVA Program 1 Create a program that will create an ArrayList of Strings. Then input names until “quit” and use the enhanced for loop to print out the names. Program 2 Using enum and array of objects Use the enumerated type of: enum CarType { PORCHE, FERRARI, JAGUAR, UNKNOWN } And place it in its own file. Then make a Car class that has the following: Make of CarType Year,...
please help ASAP me with this JAVA program! and please do correct INDENTATION with NO COMMENTS! thank you! Using enum and array of objects Use the enumerated type of: enum CarType { PORCHE, FERRARI, JAGUAR, UNKNOWN } And place it in its own file. Then make a Car class that has the following: Make of CarType Year, string or integer Mileage of integer Place in its own file like so: porche 2010 51119 ...
Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...
I need this in java please Create an automobile class that will be used by a dealership as a vehicle inventory program. The following attributes should be present in your automobile class: private string make private string model private string color private int year private int mileage. Your program should have appropriate methods such as: default constructor parameterized constructor add a new vehicle method list vehicle information (return string array) remove a vehicle method update vehicle attributes method. All methods...
Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super class. The class includes four private String instance variables: first name, last name, social security number, and state. Write a constructor and get methods for each instance variable. Also, add a toString method to print the details of the person. After that create a class Teacher which extends the class, Person. Add a private instance variable to store number of courses. Write a constructor...
(JAVA) Use the Pet.java program from the original problem (down below) Compile it. Create a text file named pets10.txt with 10 pets (or use the one below). Store this file in the same folder as your “class” file(s). The format is the same format used in the original homework problem. Each line in the file should contain a pet name (String), a comma, a pet’s age (int) in years, another comma, and a pet’s weight (double) in pounds. Perform the...
JAVA help Create a class Individual, which has: Instance variables for name and phone number of individual. Add required constructors, accessor, mutator, toString() , and equals method. Use array to implement a simple phone book , by making an array of objects that stores the name and corresponding phone number. The program should allow searching in phone book for a record based on name, and displaying the record if the record is found. An appropriate message should be displayed if...
Java : Please help me correct my code: create a single class (Program11.java) with a main method and some auxiliary methods to input a 2-D array from a disk file, input some “transactions” to change the 2-D array and output the changed 2-D array to another file. Your main method will be minimal (see below). Most of the work will go on in your methods. In main, declare (but do not instantiate) 2-D array. Then call the three methods. The...
Can you please produce the Java code that solves this non-assessed homework problem? I'm very new to Java and Object-Oriented Programming and I have no idea how to construct the logic for this code. PROBLEM: "In this exercise, you will build a program that determines the validity of a select few simple English sentences, according to rules detailed below. A sentence will be represented as an array of words, which you will create as a static nested class `Word`. `Word`...
In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program to create a database of dogs of your own. You will also include File I/O with this program. You will create 3 classes for this assignment. The first class: Create a Class representing the information that is associated with one item (one dog) of your database. Name this class Dog. Using Lab 3, this will include the information in regard to one dog. The...