You are on page 1of 43

Name : Shubham Bayas

Roll No : 66

Div : B

Experiment No : 6

Problem Statement 1

Create a new class Food in the Java project SwiftFood with the details given below.

class Food
{
     String foodName;
     String cuisine;
     String foodType;
     int quantityAvailable;
     double unitPrice;
     Food(String f,String c,String ft,int q,double u)
     {
        foodName=f;
        cuisine=c;
        foodType=ft;
        quantityAvailable=q;
        unitPrice=u;
     }
     void display()
     {
         System.out.println(foodName);
         System.out.println(cuisine);
         System.out.println(foodType);
         System.out.println(quantityAvailable);
         System.out.println(unitPrice);

     }
     public static void main(String[] ars)
     {
        Food fo=new Food("Dosa","ColdDrink","Vegetarian",67,34.98);
        fo.display();
     }
}
Problem Statement 2

Implement a class Calculator with the method mentioned below. 

Method Description
findAverage()
 Calculate the average of three numbers
 Return the average rounded off to two decimal digits

Test the functionalities using the provided Tester class. 


class Calculator {

double findAverage(int num1,int num2,int num3)

double avg=(double)(num1+num2+num3)/3;

double roundoff=Math.round(avg*100.0)/100.0;

System.out.println(roundoff);
return roundoff;

class Tester {

public static void main(String args[]) {

Calculator calculator = new Calculator();

calculator.findAverage(12,8,15);

calculator.findAverage(10,20,30);

// Invoke the method findAverage of the Calculator class and display the average

Problem Statement 3
Create a new class Order in the Java project SwiftFood with the instance variables and methods
mentioned below.

public class Order


 {
    int foodId;
    String orderedFoods;
    String status;
    double totalPrice;
    Order(int foodId,String orderedFoods,String status)
    {
        this.foodId=foodId;
        this.orderedFoods=orderedFoods;
        this.status=status;
    }
    double calculateTotalPrice(int unitPrice)
    {
          double totalPrice=(unitPrice*5)/100;
         
          System.out.println("Order Details");
        System.out.println("Order Id: "+foodId);
        System.out.println("Ordered Food: "+orderedFoods);
        System.out.println("Ordered Status: "+status);
        System.out.println("Total Price: "+totalPrice);
          return totalPrice;
         
         

    }
 
    public static void main(String[] args)
    {
        Order o=new Order(101,"Spnach Alfredo Pasta","Ordered");
        o.calculateTotalPrice(700);
     
    }
}
Problem statement 4

public class Restaurant


{
    String restaurantName;
    float rating;
    long restaurantContact;
    String restaurantAddress;
   
    void printRestaurantDetails()
    {
        System.out.println("Restaurant Details");
        System.out.println("*****************");
        System.out.println("Restaurant Name: "+restaurantName);
        System.out.println("Restaurant Rating: "+rating);
        System.out.println("Restaurant Contact: "+restaurantContact);
        System.out.println("Restaurant Address: "+restaurantAddress);
    }
    public static void main(String[] args)
    {
        Restaurant re=new Restaurant();
        re.restaurantName="McDonalds";
        re.rating=4.1f;
        re.restaurantContact=998867676;
        re.restaurantAddress="SH1109, Carolina Street, springfield";
        re.printRestaurantDetails();
    }
}

Problem statement 5

Implement a class Calculator with the instance variable and method


mentioned below. 
class Calculator {
int num;

Calculator(int num)

this.num=num;

int sumOfDigits()

int z,count=0,sum=0,digits,i;

z=num;

while(z>0)

count++;

z=z/10;

z=num;

for(i=1;i<=count;i++)

digits=z%10;

sum=sum+digits;

z=z/10;

System.out.println(sum);

return sum;

}
}

class Tester {

public static void main(String args[]) {

Calculator calculator = new Calculator(123);

calculator.sumOfDigits();

Calculator calculator1 = new Calculator(6547);

calculator1.sumOfDigits();

}
Problem statement 6

Method Description
calculateArea()
 Calculate and return the area of the rectangle. The area should be
rounded off to two decimal digits.
calculatePerimeter()
 Calculate and return the perimeter of the rectangle. The perimeter
should be rounded off to two decimal digits.
Test the functionalities using the provided Tester class. 
class Rectangle

float length;

float width;

double calculateArea(float length,float width)

double area=(double)length*width;

double roundOff=Math.round(area*100.0)/100.0;

System.out.println(roundOff);

return roundOff;

}
double calculatePerimeter(float length,float width)

double peri=(double)2*(length+width);

double round=Math.round(peri*100.0)/100.0;

System.out.println(round);

return round;

class Tester {

public static void main(String args[]) {

Rectangle rectangle=new Rectangle();

rectangle.calculateArea(12f,5f);

rectangle.calculatePerimeter(12f,5f);

Rectangle rectangle1=new Rectangle();

rectangle1.calculateArea(6f,3f);

rectangle1.calculatePerimeter(6f,3f);

}
Problem statement 7

Method Description

Order()

 Set the value of status to 'Ordered'.

Order(int orderId, String orderedFoods)

 Initialize the instance variables appropriately with the values passed to the
constructor.
 Set the value of status to 'Ordered'.
 public class Order
 {
     int orderId;
     String orderedFoods;
     Order()
     {
         System.out.println("Status of Order 1: Ordered");
         System.out.println("Status of Order 2: Ordered");
     }
     Order(int orderId,String orderedFoods)
     {
         this.orderId=orderId;
         this.orderedFoods=orderedFoods;
         System.out.println("Id of order 2: "+orderId);
         System.out.println("Items ordered in order 2: "+orderedFoods);
     }
     public static void main(String[] args)
     {
         Order or=new Order();
         Order or1=new Order(1001,"Garlic Shrimp");
     }
 }

Problem statement 8

Consider the class Employee given below for representing employees of an


organization. It has 5 different instance variables and a method to calculate
the total salary based on the jobLevel.
Salary is calculated in the calculateSalary() method.
Make necessary changes to the class by making all the attributes private and
by adding necessary accessor and mutator methods thus bringing in
Encapsulation.
class Employee {

private String employeeId;

private String employeeName;

private int salary;

private int bonus;

private int jobLevel;

public String accessorempId()

return employeeId;

public void mutatorempId(String Id)

employeeId=Id;
}

public String accessorempName()

return employeeName;

public void mutatorempName(String N)

employeeName=N;

public int accessorempSal()

return salary;

public void mutatorempSal(int s)

salary=s;

public int accessorbonus()

return bonus;

public void mutatorbonus(int d)

bonus=d;

}
public int accessorjob()

return jobLevel;

public void mutatorjob(int j)

jobLevel=j;

public void calculateSalary() {

if (this.jobLevel >= 4) {

this.bonus = 100;

} else {

this.bonus = 50;

this.salary += this.bonus;

class Tester {

public static void main(String args[]) {

Employee employee = new Employee();

employee.mutatorempId("C101");
employee.mutatorempName("Steve");

employee.mutatorempSal(650);

employee.mutatorjob(4);

employee.calculateSalary();

System.out.println("Employee Details");

System.out.println("Employee Id: " + employee.accessorempId());

System.out.println("Employee Name: " + employee.accessorempName());

System.out.println("Salary: " + employee.accessorempSal());

Problem statement 9

Make necessary changes to the Order and Food classes by making all the instance
variables private and adding getter and setter methods for the instance variables.

class Food
{
      private String foodName;
     private String cuisine;
     private String foodType;
     private int quantityAvailable;
     private double unitPrice;
     public void getfoodName(String N)
     {
        foodName=N;
     }
     public String setfoodName()
     {
      return foodName;
     }
     public void getcuisine(String C)
     {
        cuisine=C;
     }
     public String setcuisine()
     {
      return cuisine;
     }
     public void getfoodType(String F)
     {
        foodType=F;
     }
     public String setfoodType()
     {
      return foodType;
     }
     public void getquantityAvailable(int Q)
     {
         quantityAvailable=Q;
     }
     public int setquantityAvailable()
     {
      return quantityAvailable;
     }
     public void getunitPrice(int P)
     {
         unitPrice=P;
     }
     public double setunitPrice()
     {
      return unitPrice;
     }
   
     public static void main(String[] ars)
     {
        Food food=new Food();
        food.getfoodName("Dosa");
        food.getcuisine("Cold Drink");
        food.getfoodType("Vegetarian");
        food.getquantityAvailable(234);
        food.getunitPrice(23);
        System.out.println("Food Name : "+food.setfoodName());
        System.out.println("Cuisine : "+food.setcuisine());
        System.out.println("Food Type : "+food.setfoodType());
        System.out.println("Quantity : "+food.setquantityAvailable());
        System.out.println("Unit Price : "+food.setunitPrice());

     }
}

public class Order


{
    private int orderId;
    private String orderedFoods;
    public void getorderId(int O)
    {
        orderId=O;
    }
    public int setorderId()
    {
        return orderId;
    }
    public void getorderedFoods(String OF)
    {
        orderedFoods=OF;
    }
    public String setorderedFoods()
    {
        return orderedFoods;
    }
   
   
    public static void main(String[] args)
    {
        Order or=new Order();
        or.getorderId(1001);
        or.getorderedFoods("Chinese Manchurian");
        System.out.println(or.setorderId());
        System.out.println(or.setorderedFoods());

    }
}

Problem statement 10

Make the necessary changes in the code such that the member variables are
initialized with proper values and the output is generated as follows:

class Camera {

private String brand;

private double cost;

public Camera() {

this.brand = "Nikon";

public String getBrand() {

return brand;

}
public void setBrand(String brand) {

this.brand = brand;

public double getCost() {

return cost;

public void setCost(double cost) {

this.cost = cost;

class DigitalCamera extends Camera {

private int memory;

public DigitalCamera(String brand, double cost) {

this.memory = 16;

this.setBrand(brand);

this.setCost(cost);

public int getMemory() {

return memory;

public void setMemory(int memory) {

this.memory = memory;
}

class Tester {

public static void main(String[] args) {

DigitalCamera camera = new DigitalCamera("Canon",100);

System.out.println(camera.getBrand()+" "+camera.getCost()+" "+camera.getMemory());

Problem statement 10

The Point class is used for representing a point with two coordinates.

class Point

private double xCoordinate;

private double yCoordinate;

Point(double xCoordinate,double yCoordinate)

this.xCoordinate=xCoordinate;

this.yCoordinate=yCoordinate;

}
public double getxCoordinate()

return xCoordinate;

public void setxCoordinate(double xcoordinate)

this.xCoordinate=xCoordinate;

public double getyCoordinate()

return yCoordinate;

public void setyCoordinate(double ycoordinate)

this.yCoordinate=yCoordinate;

public double calculateDistance()

double distance=Math.sqrt((getxCoordinate()-0)*(getxCoordinate()-0)+(getyCoordinate()-
0)*(getyCoordinate()-0));

return Math.round(distance*100.0)/100.0;

public double calculateDistance(Point point)

double distance=Math.sqrt((point.xCoordinate-xCoordinate)*(point.xCoordinate-xCoordinate)+
(point.yCoordinate-yCoordinate)*(point.yCoordinate-yCoordinate));
return Math.round(distance*100.0)/100.0;

class Tester {

public static void main(String[] args) {

Point point1 = new Point(3.5, 1.5);

Point point2 = new Point(6, 4);

System.out.println("Distance of point1 from origin is "+point1.calculateDistance());

System.out.println("Distance of point2 from origin is "+point2.calculateDistance());

System.out.println("Distance of point1 from point2 is "+point1.calculateDistance(point2));

//Create more objects for testing your code

}
Problem Statement 11
EPay Wallet is a wallet application using which users can pay various bills.
Users can make payments only if they have enough wallet balance.

There are two kinds of users – User and PremiumUser. PremiumUser gets
reward points for every payment.

Implement the classes based on the class diagram and description given
below
class User

private int id;

private String userName;

private String emailId;

private double walletBalance;

public User(int id ,String userName,String emailId,double walletBalance)

this.id=id;

this.userName=userName;

this.emailId=emailId;

this.walletBalance=walletBalance;

}
public int getId()

return id;

public void setId(int id)

this.id=id;

public String getUserName()

return userName;

public void setUserName(String userName)

this.userName=userName;

public String getEmailId()

return emailId;

public void setEmailId(String emailId)

this.emailId=emailId;

public double getWalletBalance()


{

return walletBalance;

public void setWalletBalance(double walletBalance)

this.walletBalance=walletBalance;

public boolean makePayment(double billAmount)

if(billAmount<=getWalletBalance())

setWalletBalance(getWalletBalance()-billAmount);

return true;

return false;

class PremiumUser extends User

private int rewardPoints;

public PremiumUser(int id ,String userName,String emailId,double walletBalance)

super(id,userName,emailId,walletBalance);

}
public int getRewardPoints()

return rewardPoints;

public void setRewardPoints(int rewardPoints)

this.rewardPoints=rewardPoints;

@Override

public boolean makePayment(double billAmount)

if(billAmount<=getWalletBalance())

setRewardPoints(getRewardPoints()+(int)(billAmount*0.1));

return super.makePayment(billAmount);

class Tester {

public static void main(String[] args) {

User user = new User(101, "Joe", "joe@abc.com", 100);


PremiumUser premiumUser = new PremiumUser(201, "Jill", "jill@abc.com", 300);

processPayment(user, 70);

processPayment(premiumUser, 150);

processPayment(premiumUser, 80);

processPayment(premiumUser, 120);

public static void processPayment(User user, double billAmount) {

if (user.makePayment(billAmount)) {

System.out.println("Congratulations " + user.getUserName() + ", payment of $"


+ billAmount + " was successful!");

} else {

System.out.println("Sorry " + user.getUserName() + ", you do not have enough


balance to pay the bill!");

System.out.println("Your wallet balance is $" + user.getWalletBalance());

if (user instanceof PremiumUser) {

PremiumUser premiumUser = (PremiumUser) user;

System.out.println("You have " + premiumUser.getRewardPoints() + " points!");


}

System.out.println();

Problem Statement 12

Implement the class Bill based on the class diagram and description given
below.
class Bill
{
    //Implement your code here
    private int counter=9000;
    private String billId="B";
    private String paymentMode;
    public Bill(String paymentMode)
    {
        this.paymentMode=paymentMode;
    }
    public String getBillId()
    {
        return billId+counter;
    }
    public void setBillId(String billId)
    {
        this.billId=billId;
    }
    public String getPaymentMode()
    {
        return paymentMode;
    }
    public void setPaymentMode(String paymentMode)
    {
        this.paymentMode=paymentMode;
    }
    public int getCounter()
    {
        return counter++;
    }

class Tester {
    public static void main(String[] args) {

        Bill bill1 = new Bill("DebitCard");


        Bill bill2 = new Bill("PayPal");
       
        //Create more objects and add them to the bills array for testing your
code
             
        Bill[] bills = { bill1, bill2 };
             
        for (Bill bill : bills) {
            System.out.println("Bill Details");
            System.out.println("Bill Id: " + bill.getBillId());
            System.out.println("Payment method: " + bill.getPaymentMode());
            System.out.println();
       }
    }
}

Problem statement 13

A dance club is conducting auditions to admit interested candidates. You need to


implement a Participant class for the dance club based on the class diagram and
description given below.

class Participant
{
    //Implement your code here
    private int counter=1000;
    private String registrationId="D";
    private String name;
    private long contactNumber;
    private String city;
    public Participant(String name,long contactNumber,String city)
    {
        this.name=name;
        this.contactNumber=contactNumber;
        this.city=city;
    }
    public String getRegistrationId()
    {
        return registrationId+getCounter();
    }
    public int getCounter()
    {
        return counter++;
    }
    public void setCounter(int counter)
    {
        this.counter=counter;
    }
    public String getName()
    {
        return name;
    }
    public void setName(String name)
    {
        this.name=name;
    }
    public long getContactNumber()
    {
        return contactNumber;
    }
    public void setContactNumber(long contactNumber)
    {
        this.contactNumber=contactNumber;
    }
    public String getCity()
    {
        return city;
    }
    public void setCity(String city)
    {
        this.city=city;
    }

class Tester {

    public static void main(String[] args) {


       
        Participant participant1 = new Participant("Franklin", 7656784323L,
"Texas");
        Participant participant2 = new Participant("Merina", 7890423112L, "New
York");
       
        //Create more objects and add them to the participants array for testing
your code
       
        Participant[] participants = { participant1, participant2 };
       
        for (Participant participant : participants) {
            System.out.println("Hi "+participant.getName()+"! Your registration
id is "+participant.getRegistrationId());
        }

    }
}

Problem statement 13

A dance club is conducting auditions to admit interested candidates. You need to


implement a Participant class for the dance club based on the class diagram and
description given below.

class Participant

//Implement your code here

private static int counter=10000;

private String registrationId;

private String name;

private long contactNumber;

private String city;

public Participant(String name,long contactNumber,String city)

this.registrationId="D"+ ++Participant.counter;

this.name=name;

this.contactNumber=contactNumber;

this.city=city;

public String getRegistrationId()


{

return registrationId;

public static int getCounter()

return counter;

public static void setCounter(int counter)

Participant.counter=counter;

public String getName()

return name;

public void setName(String name)

this.name=name;

public long getContactNumber()

return contactNumber;

public void setContactNumber(long contactNumber)

{
this.contactNumber=contactNumber;

public String getCity()

return city;

public void setCity(String city)

this.city=city;

class Tester {

public static void main(String[] args) {

Participant participant1 = new Participant("Franklin", 7656784323L, "Texas");

Participant participant2 = new Participant("Merina", 7890423112L, "New York");

//Create more objects and add them to the participants array for testing your code

Participant[] participants = { participant1, participant2 };

for (Participant participant : participants) {


System.out.println("Hi "+participant.getName()+"! Your registration id is
"+participant.getRegistrationId());

Problem Statement 14

Rainbow Cinemas is an upcoming multiplex in the city with a seating


capacity of 400 people. They need an application to be developed for
booking of tickets.
You need to implement a Booking class based on the class diagram and
description given below.
class Booking
{
    private String customerEmail;
    private int seatsRequired;
    private boolean isBooked;
    private static int seatsAvailable;
    static
    {
        seatsAvailable=400;
    }
    Booking(String customerEmail,int seatsRequired)
    {
        this.customerEmail=customerEmail;
        this.seatsRequired=seatsRequired;
        if(seatsAvailable>=seatsRequired)
        {
            isBooked=true;
            seatsAvailable=seatsAvailable-seatsRequired;
        }
        else
        {
            isBooked=false;
        }
    }
    public String getCustomerEmail()
    {
        return customerEmail;
    }
    public void setCustomerEmail(String customerEmail)
    {
        this.customerEmail=customerEmail;
    }
    public int getSeatsRequired()
    {
        return seatsRequired;
    }
    public void setSeatsRequired(int seatsRequired)
    {
        this.seatsRequired=seatsRequired;
    }
    public boolean isBooked()
    {
        return isBooked;
    }
    public void setBooked(boolean isBooked)
    {
        this.isBooked=isBooked;
    }
    public static int getSeatsAvailable()
    {
        return seatsAvailable;
    }
    public static void setSeatsAvailable(int seatsAvailable)
    {
        Booking.seatsAvailable=seatsAvailable;
    }
    //Implement your code here
}

class Tester {
    public static void main(String[] args) {
        Booking booking1 = new Booking("jack@email.com", 100);
        Booking booking2 = new Booking("jill@email.com", 350);
        //Create more objects and add them to the bookings array for testing your
code
       
        Booking[] bookings = { booking1, booking2 };
             
        for (Booking booking : bookings) {
            if (booking.isBooked()) {
                System.out.println(booking.getSeatsRequired()+" seats
successfully booked for "+booking.getCustomerEmail());
            }
            else {
                System.out.println("Sorry "+booking.getCustomerEmail()+",
required number of seats are not available!");
                System.out.println("Seats available:
"+Booking.getSeatsAvailable());
            }
         }
    }
}

Problem Statement 15

You have already created the Customer class in the SwiftFood project. The address
instance variable is of type String but address itself can be represented as a
combination of doorNo, street, city and zipCode. 

So, create an Address class based on the class diagram given below and make
necessary changes to the Customer class.

 class Address
{
    private String doorNo;
    private String street;
    private String city;
    private int zipCode;
    Address(String doorNo,String street,String city,int zipCode)
    {
        this.doorNo=doorNo;
        this.street=street;
        this.city=city;
        this.zipCode=zipCode;

    }
    public String getDoorNo()
    {
        return doorNo;
    }
    public void setDoorNo(String doorNo)
    {
        this.doorNo=doorNo;
    }
    public String getStreet()
    {
        return street;
    }
    public void setStreet(String street)
    {
        this.street=street;
    }
    public int getZipCode()
    {
        return zipCode;
    }
    public void setZipCode(int zipCode)
    {
        this.zipCode=zipCode;
    }
    public String getCity()
    {
        return city;
    }
    public void setCity(String city)
    {
        this.city=city;
    }
}
 class Customer
{
    private String customerId;
    private String customerName;
    private long contactNumber;
    private Address address;
    Customer() {}
    Customer(String customerId,String customerName,long contactNumber,Address
address)
    {
       
        this.customerId=customerId;
        this.customerName=customerName;
        this.contactNumber=contactNumber;
        this.address=address;
    }
    Customer(String customerId,String customerName,Address address)
    {
       
        this.customerId=customerId;
        this.customerName=customerName;
        this.address=address;
    }
    public String getCustomerId()
    {
        return customerId;
    }
    public void setCustomerId(String customerId)
    {
        this.customerId=customerId;
    }
    public String getCustomerName()
    {
        return customerName;
    }
    public void setCustomerName(String customerName)
    {
        this.customerName=customerName;
    }
    public long getContactNumber()
    {
        return contactNumber;
    }
    public void setContactNumber(long contactNumber)
    {
        this.contactNumber=contactNumber;
    }
    public Address getAddress()
    {
        return address;
    }
    public void setAddress(Address address)
    {
        this.address=address;
    }
    public void displayCustomerDetails()
    {
         System.out.println("Customer ID: "+getCustomerId());
         System.out.println("Name: "+getCustomerName());
         System.out.println("Contact no: "+getContactNumber());
         System.out.println("Address: ");
         System.out.println("\tDoor No: "+address.getDoorNo());
         System.out.println("\tStreet: "+address.getStreet());
         System.out.println("\tCity: "+address.getCity());
         System.out.println();

    }
    public double payBill(double totalPrice)
    {
            return totalPrice;
    }
    public static void main(String[] args)
    {
        Address a1=new Address("A45","xy road","Hyderabad",500012);
   
        Customer c1=new Customer("101","Parag",890000000,a1);
        c1.displayCustomerDetails();
    }
}

Problem statement 16
You need to develop an application for cab service providers by implementing the
classes based on the class diagram and description given below.

package associationEx1;
class CabServiceProvider
{
    //Implement your code here
    private String cabServiceName;
    private int totalCab;
    public double rewardPrice;
    CabServiceProvider(String cabServiceName,int totalCab)
    {
        this.cabServiceName=cabServiceName;
        this.totalCab=totalCab;
    }
    public String getCabServiceName()
    {
        return cabServiceName;
    }
    public void setCabServiceName(String cabServiceName)
    {
        this.cabServiceName=cabServiceName;
    }
    public int getTotalCab()
    {
        return totalCab;
    }
    public void setTotalCab(int totalCab)
    {
        this.totalCab=totalCab;
    }
    double calculateRewardPrice(Driver driver)
    {
        if(cabServiceName=="Halo")
        {
            if(driver.getAverageRating()>=4.5 && driver.getAverageRating()<=5)
            {
                rewardPrice=10*driver.getAverageRating();
            }
            else if(driver.getAverageRating()>=4 &&
driver.getAverageRating()<=4.5)
            {
                rewardPrice=5*driver.getAverageRating();

            }
            else
            {
                return rewardPrice=0;
            }
        }
        else if(cabServiceName=="Aber")
        {
            if(driver.getAverageRating()>=4.5 && driver.getAverageRating()<=5)
            {
                rewardPrice=8*driver.getAverageRating();
            }
            else if(driver.getAverageRating()>=4 &&
driver.getAverageRating()<=4.5)
            {
                rewardPrice=3*driver.getAverageRating();

            }
            else
            {
                return rewardPrice=0;
            }
        }
        else
        {
            return rewardPrice;
        }
    }
}

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 might also like