Menu
Question Index
...


Implement the upgrade method in the Car class, which upgrades the features depending upon the money available. The upgrades available are AC (Rs. 21500), Leather Seats (Rs. 14400), Back Wipers (Rs. 6250) and Fog Lights (Rs. 3300). Whatever upgrades are possible have to be made. e.g., It’s not necessary that we have to upgrade AC before Leather Seats, and we can upgrade Fog Lights without AC or Leather Seats etc.,

Input (Available Amount) Output (Upgraded Car, Remaining Amount)
25000 AC and Fog Lights Installed
Remaining Amount = (25000 - 21500 - 3300) = 200
40000 AC, Leather Seats and Fog Lights Installed
Remaining Amount = (40000 - 21500 - 14400 - 3300) = 800
50500 AC, Leather Seats, Back Wipers and Fog Lights Installed
Remaining Amount = (50500 - 21500 - 14400 - 6250 - 3300) = 5050

class UpgradeCar

{    public static void main(String s[])
    {
        Car sanjeev_santro = new Car("Sanjeev", "Santro");
        
        double availableAmount = 40000.0;
        double remainingAmount = sanjeev_santro.upgradeCar(availableAmount);
        
        System.out.println("Available Amount Before Upgrade : " + availableAmount);
        System.out.println("Installed AC : " + sanjeev_santro.hasAC);
        System.out.println("Installed Leather Seats : " + sanjeev_santro.hasLeatherSeats);
        System.out.println("Installed Back Wipers : " + sanjeev_santro.hasBackWipers);
        System.out.println("Installed Fog Lights : " + sanjeev_santro.hasFogLights);
        System.out.println("Amount After Upgrade : " + remainingAmount);

    }


}
class Car
{
String ownerName;
String model;

Car(String ownerName, String model)
{
this.ownerName = ownerName;
this.model = model;
}

boolean hasAC = false;
boolean hasLeatherSeats = false;
boolean hasBackWipers = false;
boolean hasFogLights = false;

double upgradeCar(double availableAmount)
{
//Write code here to upgrade the car depending upon the available amount. If there is any remaining balance, it has to be returned.
}
}

Doubts

Problems

Topic: Behavior Of Java Classes Using Methods

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App