Link to home
Start Free TrialLog in
Avatar of USN4x4
USN4x4

asked on

overloading program

The program overloads the getFinalPrice() method.

int getFinalPrice(boolean ac, boolean cd)

int getFinalPrice(boolean ac, boolean cd, int discount)

The second method is for friends of the dealer. When you invoke getFinalPrice() with
three arguments, the second one will be invoked, giving a discount. The third
argument specifies the percentage of discount.

Include one more overloaded method,
getFinalPrice(Boolean ac, Boolean cd, int discount, double tax).
This method adds tax amount to the final price.

Write the complete program and test all your methods.

Having problems getting the final outputs to match the above criteria, can you please assist? thanks
class OverLoadingMethods
{
public static void main(String[] args)
{
Autos carl = new Autos("Toyota","Camry",18000,6);
System.out.println("Final price for carl, with AC and CD "+
carl.getFinalPrice(true,true));
System.out.println("Same car for a good friend"+
carl.getFinalPrice(true,true,10));
}
class Autos
{
private String make;
private String model;
private int base_price;
private int cylinders;
Autos(String mk, String md, int bp, int cy)
{
make = mk;
model = md;
base_price = bp;
cylinders = cy;
}
int getFinalPrice(boolean ac, boolean cd)
{
int price = base_price;
if (ac) price += 500;
if(cd) price += 300;
return (price);
}
int getFinalPrice(boolean ac, boolean cd, int discount)
{
int price = base_price;
if (ac) price += 500;
if (cd) price += 300;
return (price - (price*discount/100));
}
}

Open in new window

Avatar of Todd Mummert
Todd Mummert


This is a class assignment...  general help only


add the "double tax" argument to another copy of the last getFinalPrice() function above

then when you calculate the return value just multiply by (1+tax amount) -- (assuming it is given as 0.06, and not 6, for example)..  if the latter, you will have to do something like  (1+tax_amount)/100
ASKER CERTIFIED SOLUTION
Avatar of avdej
avdej
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial