Limited access

Upgrade to access all content for this subject

Consider the following class.

public class Car
{
    /** params mk = make
      * md = model
      * dist = distance driven
      * gals = gallons used
    */
    public Car(String mk, String md, int dist, int gals)
    {   /* implementation not shown */  }

    public void setMake(String mk)   // Set the Car make
    {   /* implementation not shown */  }

    public void setModel(String md)  // Set the Car model
    {   /* implementation not shown */  }

    // Set distance and gallons
    public void setDistanceAndGallons(int dist, int gals)  
    {   /* implementation not shown */  }

    public String getMake()   // Get the Car make
    {   /* implementation not shown */  }

    public String getModel()   // Get the Car model
    {   /* implementation not shown */  }

    /** returns the miles per gallon by dividing distance 
     * driven by gallons used
     */
    public double calcMPG()    
    {   /* implementation not shown */  }

    public String toString()  
    {
        return make + "" + model + "gets" + calcMPG() + 
            "miles per gallon";
    }  
}

Also, given the following method from a client class:

public static Car changeModel(Car myCar, 
            String make, String model)
{
    if (myCar.getMake().equals(make))
    {
        myCar.setModel(model);
    }
    return myCar;
}

What will print when the following segment of code is executed?

Car origCar = new Car("Ford", "Mustang", 100, 5);
Car newCar = changeModel(origCar, "Ford", "Mustang GT");
newCar.setDistanceAndGallons(150, 10);
System.out.println("origCar =" + origCar);
System.out.println("newCar =" + newCar);
A
origCar = Ford Mustang gets 20.0 miles per gallon
newCar = Ford Mustang GT gets 15.0 miles per gallon
B
origCar = Ford Mustang GT gets 20.0 miles per gallon
newCar = Ford Mustang GT gets 15.0 miles per gallon
C
origCar = Ford Mustang GT
newCar = Ford Mustang GT
D
origCar = Ford Mustang
newCar = Ford Mustang GT
E
origCar = Ford Mustang GT gets 15.0 miles per gallon
newCar = Ford Mustang GT gets 15.0 miles per gallon
Select an assignment template