Create a class named Price this class contains three private

Create a class named \"Price\", this class

contains three private fields: price, quantity, couponvalue

Methods to get and set each of the fields

one constructor with three parameters, these three parameters can initialize price, quantity and coupon value as specified (for instance, 20, 10, 5)

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, get and set methods, and computeprice() methoduse system.out.println() to show different results

Solution

/* package whatever; // don\'t place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be \"Main\" only if the class is public. */
class Ideone
{
   private int   price, quantity, couponvalue ;
   Ideone(int price, int quantity,int couponvalue )
   {
       this.price=price;
       this.quantity=quantity;
       this.couponvalue=couponvalue;
       System.out.println(\"price,quantity and couponvalue are \"+price+ \" \" +quantity + \" \" +couponvalue);
   }
       public int getprice()
       {
       return this.price;
       }
       public int getquantity()
       {
       return this.quantity;
       }
      
       public int getcouponvalue()
       {
       return this.couponvalue;
       }
      
       public void setprice(int price)
       {
       //include more logic
       this.price = price;
       }
      
       public void setquantity(int quantity)
       {
       //include more logic
       this.quantity = quantity;
       }
      
       public void setcouponvalue(int couponvalue)
       {
       //include more logic
       this.couponvalue = couponvalue;
       }
       public double computeprice(int price, int quantity, int couponvalue)
       {
           double result ;
           result = (price*quantity) - couponvalue;
           result = result + (0.2*result);
           return result;
          
       }
  
   public static void main (String[] args) throws java.lang.Exception
   {
       Ideone s = new Ideone(10,2,3);
       int a =s.getprice();
       System.out.println(\"price before setting \"+a);
       int b = s.getquantity();
       System.out.println(\"quantity before setting \"+b);
       int c = s.getcouponvalue();
       System.out.println(\"couponvalue is \"+c);
       s.setprice(20);
       s.setquantity(4);
       s.setcouponvalue(5);
       a =s.getprice();
       System.out.println(\"price afer setting \"+a);
       b = s.getquantity();
       System.out.println(\"quantity afer setting \"+b);
       c = s.getcouponvalue();
       System.out.println(\"couponvalue afer setting \"+c);
  
       double total = s.computeprice(10,2,3);
       System.out.println(\"total is\"+ total);
      
   }
}

Create a class named \
Create a class named \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site