Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Sammy Samkough
- public interface Item
- {
- double purchasePrice();
- }
- -------------------------------------------------------------------------------------------------------------------------------
- // Sammy Samkough
- public abstract class TaxableItem implements Item
- {
- private double taxRate;
- public abstract double getListPrice();
- public TaxableItem(double rate)
- {
- taxRate = rate;
- }
- // Part A
- // returns the price of the item including the tax
- public double purchasePrice()
- {
- double purchasePrice = getListPrice() * (1 + taxRate);
- return purchasePrice;
- }
- /** Added the getTaxRate() Accessor Method */
- public double getTaxRate()
- {
- return taxRate;
- }
- }
- -------------------------------------------------------------------------------------------------------------------------------
- // Sammy Samkough
- // Part B - Create the Vehicle class which extends the TaxableItem class.
- // * A vehicle has two parts to its list price: a dealer cost and dealer markup.
- // * The list price of a vehicle is the sum of the dealer cost and the dealer markup.
- // * Your class should have a constructor that takes dealer cost, dealer markup, and the tax rate as parameters.
- // * Provide any instance variables needed and implement all necessary methods.
- // * Also provide a public method changeMarkup, which changes the dealer markup to the value of its parameter.
- public class Vehicle extends TaxableItem
- {
- /* Instance Variables not shown - read the comments for Part B above */
- private int dealerCost;
- private int dealerMarkup;
- private int taxRate;
- /* Class Methods not shown - read the comments for Part B above */
- public Vehicle(double tRate)
- {
- super(tRate);
- dealerCost = 0;
- dealerMarkup = 0;
- }
- public Vehicle(int dCost, int dMarkup, double tRate)
- {
- super(tRate);
- tRate = taxRate;
- dealerCost = dCost;
- dealerMarkup = dMarkup;
- }
- public void changeMarkup(int cMarkup)
- {
- dealerMarkup = cMarkup;
- }
- public double getListPrice()
- {
- return dealerCost + dealerMarkup;
- }
- public double getPurchaseCost()
- {
- return getListPrice() + (1 + taxRate);
- }
- /*** Not specifically asked for in question - but toString() should be added here to allow a client to print
- * Label and print out the Dealer Cost, Dealer Markup, List Price, Tax Rate and Purchase Price
- */
- public String toString()
- {
- String result = "";
- result += "Dealer Cost: " + dealerCost + " Dealer Markup: " + dealerMarkup;
- return result;
- }
- }
- -------------------------------------------------------------------------------------------------------------------------------
- // Sammy Samkough
- import java.util.ArrayList;
- public class VehicleRunner
- {
- public static void main(String[] args)
- {
- Vehicle one = new Vehicle(25000, 3200, .07);
- Vehicle two = new Vehicle(33000, 4300, .07);
- Vehicle three = new Vehicle(51000, 6000, .07);
- ArrayList<Vehicle> cars = new ArrayList<Vehicle>();
- cars.add(one);
- cars.add(two);
- cars.add(three);
- System.out.println(cars);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement