Sunday, 20 November 2022

Association - Exercise 1

 

Association - Exercise 1


You need to develop an application for cab service providers by implementing the classes based on the class diagram and description given below.    Note: Driver class is provided to you.  Method Description  CabServiceProvider  CabServiceProvider(String cabServiceName, int totalCabs)  Initialize all the instance variables appropriately with the values passed to the constructor. calculateRewardPrice(Driver driver)  Calculate and return the bonus of the driver based on the below table. If averageRating of the driver is less than 4, return the bonus as 0.                  In case of any invalid value, return the bonus as 0.  Note: Round off the bonus to 2 decimal digits.  Implement the appropriate getter and setter methods.  Perform case-sensitive comparison wherever applicable.  Test the functionalities using the provided Tester class.      Sample Input and Output  Input  For CabServiceProvider object cabServiceProvider1 with cabServiceName = Halo and totalCabs = 50  Driver object - driver1    Driver object - driver2    Driver object - driver3    Output,coding savior,infosys assignment quiz and lex genrric ansewer,infosys generic java program, code answer,code saviour,code monk,coding bar,code solution for infosys  assignmenet,code saviour trend



class CabServiceProvider{
private static final String String=null;
private String cabServiceName;
private int totalCabs;
public CabServiceProvider(String cabServiceName,int totalCabs){
this.cabServiceName=cabServiceName;
this.totalCabs=totalCabs;
}
public String getCabServiceName(){
return cabServiceName;
}
public void setCabServiceName(String cabServiceName){
this.cabServiceName=cabServiceName;
}
public int getTotalCabs(){
return totalCabs;
}
public  void setTotalCabs(int totalCabs){
this.totalCabs=totalCabs;
}
public double calculateRewardPrice(Driver driver){
double bonus=0.0;
double rewardAmount=0.0;
if(cabServiceName.equals("Halo")){
if(driver.getAverageRating()>=4.5&&driver.getAverageRating()<=5){
rewardAmount=10*driver.getAverageRating();
}
else if(driver.getAverageRating()>=4&&driver.getAverageRating()<4.5){
rewardAmount=5*driver.getAverageRating();
}
else{
rewardAmount=0.0;
}
}
else if(cabServiceName.equals("Aber")){
if(driver.getAverageRating()>=4.5&&driver.getAverageRating()<=5){
rewardAmount=8*driver.getAverageRating();
}
else if(driver.getAverageRating()>=4&&driver.getAverageRating()<4.5){
rewardAmount=3*driver.getAverageRating();
}
else{
rewardAmount=0.0;
}
}
else{
rewardAmount=0.0;
}
bonus=Math.round(rewardAmount*100.0)/100.0;
return bonus;
}
}

class Driver {
   
    private String driverName;
    private float averageRating;
   
    public Driver(String driverName, float averageRating){
        this.driverName=driverName;
        this.averageRating=averageRating;
    }
   
    public String getDriverName(){
        return this.driverName;
    }
   
    public void setDriverName(String driverName){
        this.driverName=driverName;
    }
   
    public float getAverageRating(){
        return this.averageRating;
    }
   
    public void setAverageRating(float averageRating){
        this.averageRating=averageRating;
    }

    //DO NOT MODIFY THE METHOD
    //Your exercise might not be verified if the below method is modified
    public String toString(){
        return "Driver\ndriverName: "+this.driverName+"\naverageRating: "+this.averageRating;
    }
}

class Tester {
   
    public static void main(String args[]){
        CabServiceProvider cabServiceProvider1 = new CabServiceProvider("Halo", 50);

        Driver driver1 = new Driver("Luke", 4.8f);
        Driver driver2 = new Driver("Mark", 4.2f);
        Driver driver3 = new Driver("David", 3.9f);
       
        Driver[] driversList = { driver1, driver2, driver3 };
        for (Driver driver : driversList) {
            System.out.println("Driver Name: "+driver.getDriverName());
            double bonus = cabServiceProvider1.calculateRewardPrice(driver);
            if (bonus>0)
                System.out.println("Bonus: $"+bonus+"\n");
            else
                System.out.println("Sorry, bonus is not available!");
        }
       
        //Create more objects of CabServiceProvider and Driver classes for testing your code
    }
}

You need to develop an application for cab service providers by implementing the classes based on the class diagram and description given below.    Note: Driver class is provided to you.  Method Description  CabServiceProvider  CabServiceProvider(String cabServiceName, int totalCabs)  Initialize all the instance variables appropriately with the values passed to the constructor. calculateRewardPrice(Driver driver)  Calculate and return the bonus of the driver based on the below table. If averageRating of the driver is less than 4, return the bonus as 0.                  In case of any invalid value, return the bonus as 0.  Note: Round off the bonus to 2 decimal digits.  Implement the appropriate getter and setter methods.  Perform case-sensitive comparison wherever applicable.  Test the functionalities using the provided Tester class.      Sample Input and Output  Input  For CabServiceProvider object cabServiceProvider1 with cabServiceName = Halo and totalCabs = 50  Driver object - driver1    Driver object - driver2    Driver object - driver3    Output


No comments:

Post a Comment

Free Resume Template

Creating a blog post that discusses the pros and cons of using a resume rule is a great way to provide valuable information to job seekers ...