Question

In: Computer Science

You have been assigned to a development team that is building software that will be used...

You have been assigned to a development team that is building software that will be used to control the operations of a bicycle rental store. A rental store has a limited number of vehicles that can be managed. A bicycle rental store must maintain information about how many vehicles are available for rental. The bicycle rental store must provide publicly available methods to allow vehicles to be added and removed from it. The rental store should also provide publicly available methods that reports its capacity. An attempt to add or remove the vehicle other than it’s capacity should print the message letting user know that he/she can’t add or delete the vehicle (Hint: use “if” condition to check the number of vehicles. They shouldn’t be more that 5/5 each to add and less than 1 to delete). At the moment there are two distinct types of vehicles: bicycle and quadricycle (four-wheel bicycle). Every vehicle has a company code, a fun name, number of wheels and a rental price. The bicycle has two wheels whereas quadricycle has four. Define the Java classes that are required to implement the functionality that is described above. Be sure to use object-oriented principles in your Java code. Hints • Vehicle class, Bicycle class, Quadricycle class, RentalStore class. • Bicycle class and Quadricycle class inherits extends from Vehicle class • RentalStore class will have methods to show the total number of vehicles, add/delete Bicycle and add/delete Quadricycle • Rental class should have ArrayList • In general every class should have attributes, constructor and it’s methods. • Besides RentalStore class, all other classes should have toString() method . • Create TestClass that have Main() method. Bicycles: company code 0001, a fun name ( your choice), number of wheels : 2 and a rental price 150 company code 0002, a fun name ( your choice), number of wheels : 2 and a rental price 110 company code 0003, a fun name ( your choice), number of wheels : 2 and a rental price 50 company code 0004, a fun name ( your choice), number of wheels : 2 and a rental price 250 company code 0005, a fun name ( your choice), number of wheels : 2 and a rental price 90 quadricycle : company code 0011, a fun name ( your choice), number of wheels : 4 and a rental price 250 company code 0012, a fun name ( your choice), number of wheels : 4 and a rental price 110 company code 0013, a fun name ( your choice), number of wheels : 4 and a rental price 210 company code 0014, a fun name ( your choice), number of wheels : 4 and a rental price 210 company code 0015, a fun name ( your choice), number of wheels : 4 and a rental price 190 For this scenario, we will have 5 bicycles and 5 quadricycles (total of 10 vehicles). Add all those vehicles to an ArrayList. Find bicycles with price less than $100 and delete all of them. Find quadricycles with price less than $200 and delete all of them. At last, show to total number of remaining vehicles with their details.

Solutions

Expert Solution

Vehicle.java

public class Vehicle {

   public int companyCode;
   public String funName;
   public int numberOfWheels;
   public int rentalPrice;
  
  

   public Vehicle(int companyCode, String funName, int numberOfWheels, int rentalPrice) {
       super();
       this.companyCode = companyCode;
       this.funName = funName;
       this.numberOfWheels = numberOfWheels;
       this.rentalPrice = rentalPrice;
   }

  
  
   public int getRentalPrice() {
       return rentalPrice;
   }

   public void setRentalPrice(int rentalPrice) {
       this.rentalPrice = rentalPrice;
   }

   public int getCompanyCode() {
       return companyCode;
   }

   public void setCompanyCode(int companyCode) {
       this.companyCode = companyCode;
   }

   public String getFunName() {
       return funName;
   }

   public void setFunName(String funName) {
       this.funName = funName;
   }

   public int getNumberOfWheels() {
       return numberOfWheels;
   }

   public void setNumberOfWheels(int numberOfWheels) {
       this.numberOfWheels = numberOfWheels;
   }

   @Override
   public String toString() {
       return "Vehicle [companyCode=" + companyCode + ", funName=" + funName + ", numberOfWheels=" + numberOfWheels
               + ", rentalPrice=" + rentalPrice + "]";
   }

  
  
  
}

Bicycle.java

public class Bicycle extends Vehicle{
  
  
  

   public Bicycle(int companyCode, String funName, int numberOfWheels, int rentalPrice) {
       super(companyCode, funName, numberOfWheels, rentalPrice);
       // TODO Auto-generated constructor stub
   }

   @Override
   public int getCompanyCode() {
       // TODO Auto-generated method stub
       return super.getCompanyCode();
   }

   @Override
   public void setCompanyCode(int companyCode) {
       // TODO Auto-generated method stub
       super.setCompanyCode(companyCode);
   }

   @Override
   public String getFunName() {
       // TODO Auto-generated method stub
       return super.getFunName();
   }

   @Override
   public void setFunName(String funName) {
       // TODO Auto-generated method stub
       super.setFunName(funName);
   }

   @Override
   public int getNumberOfWheels() {
       // TODO Auto-generated method stub
       return super.getNumberOfWheels();
   }

   @Override
   public void setNumberOfWheels(int numberOfWheels) {
       // TODO Auto-generated method stub
       super.setNumberOfWheels(numberOfWheels);
   }

   @Override
   public String toString() {
       // TODO Auto-generated method stub
       return super.toString();
   }

  

  

}

Quadricycle.java

public class Quadricycle extends Vehicle{
  
  
  
  
  
   public Quadricycle(int companyCode, String funName, int numberOfWheels, int rentalPrice) {
       super(companyCode, funName, numberOfWheels, rentalPrice);
       // TODO Auto-generated constructor stub
   }

   @Override
   public int getRentalPrice() {
       // TODO Auto-generated method stub
       return super.getRentalPrice();
   }

   @Override
   public void setRentalPrice(int rentalPrice) {
       // TODO Auto-generated method stub
       super.setRentalPrice(rentalPrice);
   }

   @Override
   public int getCompanyCode() {
       // TODO Auto-generated method stub
       return super.getCompanyCode();
   }

   @Override
   public void setCompanyCode(int companyCode) {
       // TODO Auto-generated method stub
       super.setCompanyCode(companyCode);
   }

   @Override
   public String getFunName() {
       // TODO Auto-generated method stub
       return super.getFunName();
   }

   @Override
   public void setFunName(String funName) {
       // TODO Auto-generated method stub
       super.setFunName(funName);
   }

   @Override
   public int getNumberOfWheels() {
       // TODO Auto-generated method stub
       return super.getNumberOfWheels();
   }

   @Override
   public void setNumberOfWheels(int numberOfWheels) {
       // TODO Auto-generated method stub
       super.setNumberOfWheels(numberOfWheels);
   }

   @Override
   public String toString() {
       // TODO Auto-generated method stub
       return super.toString();
   }

  

  

}

RentalStore.java

public class RentalStore {
  
   ArrayList<Vehicle> vehicles;
   int bicycles=0;
   int quadricycles=0;
  
   public RentalStore() {
      
       vehicles= new ArrayList<>();
   }

   public ArrayList<Vehicle> getVehicles() {
       return vehicles;
   }

   public void setVehicles(ArrayList<Vehicle> vehicles) {
       this.vehicles = vehicles;
   }

   public int getBicycles() {
       return bicycles;
   }

   public void setBicycles(int bicycles) {
       this.bicycles = bicycles;
   }

   public int getQuadricycles() {
       return quadricycles;
   }

   public void setQuadricycles(int quadricycles) {
       this.quadricycles = quadricycles;
   }
  
   public void addVehicle(Vehicle vehicle) {
      
       if(vehicle.getNumberOfWheels()==2) {
          
           if(bicycles<5) {
               vehicles.add(vehicle);
               System.out.println("Bicycle is added Successfully");
           }
           else
               System.out.println("More than 5 Bicycles are not allowed");
       }
      
       else {
           if(quadricycles<5) {
               vehicles.add(vehicle);
               System.out.println("Quadricycle is added successfully");
           }
           else
               System.out.println("More than 5 Quadricycles are not allowed");
       }
   }
  
   public void removeVehicle(Vehicle vehicle) {
      
       int index = vehicles.indexOf(vehicle);
      
       vehicles.remove(index);
   }

}

TestClass.java

import java.util.ArrayList;

public class TestClass {

   public static void main(String[] args) {
       // TODO Auto-generated method stub

       RentalStore store = new RentalStore();
      
       store.addVehicle(new Bicycle(0001,"ammy",2,150));
       store.addVehicle(new Bicycle(0002,"bammy",2,110));
       store.addVehicle(new Bicycle(0003,"cammy",2,50));
       store.addVehicle(new Bicycle(0004,"dammy",2,250));
       store.addVehicle(new Bicycle(0005,"eammy",2,90));
      
      
      
       store.addVehicle(new Quadricycle(0011,"fammy",4,250));
       store.addVehicle(new Quadricycle(0012,"gammy",4,110));
       store.addVehicle(new Quadricycle(0013,"hammy",4,210));
       store.addVehicle(new Quadricycle(0014,"jammy",4,210));
       store.addVehicle(new Quadricycle(0011,"kammy",4,190));
      
       ArrayList<Vehicle> vehicles = store.getVehicles();
      
       for(int i=0;i<vehicles.size();i++) {
          
           if(vehicles.get(i).numberOfWheels==2 && vehicles.get(i).getRentalPrice()<100)
               store.removeVehicle(vehicles.get(i));
          
           if(vehicles.get(i).numberOfWheels==4 && vehicles.get(i).getRentalPrice()<200)
               store.removeVehicle(vehicles.get(i));
       }
      
       vehicles= store.getVehicles();
      
       for(Vehicle vehicle:vehicles)
           System.out.println(vehicle);
      
   }

}

Output

Bicycle is added Successfully
Bicycle is added Successfully
Bicycle is added Successfully
Bicycle is added Successfully
Bicycle is added Successfully
Quadricycle is added successfully
Quadricycle is added successfully
Quadricycle is added successfully
Quadricycle is added successfully
Quadricycle is added successfully
Vehicle [companyCode=1, funName=ammy, numberOfWheels=2, rentalPrice=150]
Vehicle [companyCode=2, funName=bammy, numberOfWheels=2, rentalPrice=110]
Vehicle [companyCode=4, funName=dammy, numberOfWheels=2, rentalPrice=250]
Vehicle [companyCode=9, funName=fammy, numberOfWheels=4, rentalPrice=250]
Vehicle [companyCode=11, funName=hammy, numberOfWheels=4, rentalPrice=210]
Vehicle [companyCode=12, funName=jammy, numberOfWheels=4, rentalPrice=210]

Screenshot

Feel free to ask any doubts, if you face any difficulty in understanding.

Please upvote the answer if you find it helpful


Related Solutions

You have been assigned to lead a project team. You have been given a lot of latitude in how you will lead this team.
You have been assigned to lead a project team. You have been given a lot of latitude in how you will lead this team. Think about all of the aspects involved in planning, organizing, staffing, leading and controlling this project team. Write a two-page paper on what the five functions of management mean and how you would utilize each of them to successfully put together and lead this project team. Planning 2. Organizing 3. Staffing 4. Coordinating 5. Controlling
You have be assigned to lead a project team. You have been given a lot of...
You have be assigned to lead a project team. You have been given a lot of latitude in how you will lead this team.
You have been recently assigned as the manager for the audit of Layton Co, a software...
You have been recently assigned as the manager for the audit of Layton Co, a software engineering company whose securities are publicly traded. You are filling in for your colleague, Luke Paolo, who has taken a sick leave at short notice. The company's audit for the financial year ended 30 June 20Y0 is nearing completion and its draft financial statements recognize a profit before tax of $65.4 million and total assets of $27.9 million. You are in the midst of...
You have been appointed as a team leader to a group of auditors assigned to assess...
You have been appointed as a team leader to a group of auditors assigned to assess RMZ Trading, a big retail store selling mobile phones in Nizwa. The store has been operating in Nizwa for the past five years and has been doing well. It has many customers and income is coming in. Because of this, the store is usually keeping a large stock of its inventory of mobile phones, in varying brands and models. While analyzing the inventory of...
you have been assigned to a short term team, made up of people you have never...
you have been assigned to a short term team, made up of people you have never met. What can you do to make your first meeting with your new team productive?
Imagine that you are a system analyst of a software development company and you have been...
Imagine that you are a system analyst of a software development company and you have been assigned to a team that will be developing the information systems for the clients. For now as a team leader for the data design team, you have been asked to the read and understand the following case studies and prepare the data design as specified. Creating an Entity Relationship Diagram, Creating a Context Level Data Flow Diagram. Create the ER diagram for library management...
You will play the role of a paralegal in a software development company. You have been...
You will play the role of a paralegal in a software development company. You have been given the task of recommending the type of license agreement that should be used for your company’s new software product line. Consider all types of license agreements in making the recommendation. The software delivery method should also be considered.
You have just been hired as a GIS specialist to join a team of professionals assigned...
You have just been hired as a GIS specialist to join a team of professionals assigned to identify a viable site for a new transit station. Make a detailed documentation of how GIS can be used to successfully achieve the objective of the project (i.e., identification of a new transit station). Make a genuine effort to incorporate in your documentation how the following GIS features can be leveraged: Thematic mapping Buffering Geocoding TIGER files Layers (coverage) Digitizing
You have been recently appointed as team leader in the research and development unit of an...
You have been recently appointed as team leader in the research and development unit of an important pharmaceutical company. The team is composed of seven team members. The team members have the similar educational and social background. They are usually feeling that every member of the team has the exactly the same idea with each other. In the long run, this situation will have a negative effect on their team performance. In addition, The team you are heading has been...
You have been assigned as the audit team leader of Bank Salalah, a medium-sized bank, for...
You have been assigned as the audit team leader of Bank Salalah, a medium-sized bank, for the end of year audit. Your firm is a newly appointed audit firm of the bank. The bank has been operating in the last three years and has a plan of establishing its second branch to be located also in Salalah. Informal discussions with some employees disclose that employees are happy with the bank because “there are just few rules to follow”. However, your...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT