Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Eclipse-Please provide code! Create a class named \"Price\", this class con

ID: 3677882 • Letter: J

Question

Java Eclipse-Please provide code!

Create a class named "Price", this class contains

-three instance variables: price, quantity, couponvalue

-one constructor with three parameters, these three parameters can initialize price, quantity and coupon value as specified

- two overloaded computeprice() methods:

            computeprice() method with two parameters, they represent the price of a meal and the quantity ordered. Multiple the two values, add 20% tip, and return the total price.

            computeprice() method with three parameters, they represent the price of a meal , the quantity ordered and a coupon value. Multiple the price and quantity, reduce the result by the coupon value, and then add 20% tip and return the total price.

The class should contain a main() method which tests constructor method and two computeprice() methods.

Explanation / Answer

public class Price {

   double price;
   int quantity;
   double couponvalue;

   /**
   * @param price
   * @param quantity
   * @param couponvalue
   */
   public Price(double price, int quantity, double couponvalue) {
       this.price = price;
       this.quantity = quantity;
       this.couponvalue = couponvalue;
   }

   /**
   * @param price
   * @param quantity
   * @return
   */
   public double computeprice(double price, int quantity) {

       double totalPrice;

       double totalPriceQuantity = price * quantity;

       totalPrice = totalPriceQuantity + (totalPriceQuantity * (20.0 / 100.0));

       return totalPrice;
   }

   /**
   * @param price
   * @param quantity
   * @param couponvalue
   * @return
   */
   public double computeprice(double price, int quantity, double couponvalue) {

       double totalPrice;

       totalPrice = computeprice(price, quantity);
       totalPrice -= couponvalue;
       return totalPrice;
   }

   /**
   * @param args
   */
   public static void main(String[] args) {
       Price price = new Price(200, 2, 100);
       System.out.println("computePrice(200, 2) :"
               + price.computeprice(200, 2));
       System.out.println("computePrice(200, 2,100) :"
               + price.computeprice(200, 2, 100));

   }
}

OUTPUT:

computePrice(200, 2) :480.0
computePrice(200, 2,100) :380.0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote