Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. public class Product
  2. {
  3.     private double price;
  4.     private String name;
  5.  
  6.     /**
  7.       Constructs a product with a given name and price.
  8.       @param name the name
  9.       @param price the price
  10.    */
  11.     public Product(String n, double p)
  12.     {name = n;
  13.      price = p;}
  14.  
  15.     /**
  16.       Gets the product name.
  17.       @return the name
  18.    */
  19.    public String getName()
  20.    { return name;}
  21.  
  22.    /**
  23.       Gets the product price.
  24.       @return the price
  25.    */
  26.    public double getPrice()
  27.    { return price; }
  28.  
  29.    /**
  30.       Reduces the product price.
  31.       @param amount the amount by which to reduce the price
  32.    */
  33.    public double reducePrice(double amount)
  34.    {  return price = price - amount;}
  35.  
  36.    public double price()
  37.    { return price;
  38.    }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement