Advertisement
scaawt

Lab11

Oct 15th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. /**
  2.  * written by tariq scott
  3.  */
  4. public class Apple {
  5.  
  6. // variables
  7.   private String name;
  8.   private double weight;
  9.   private double price;  
  10.  
  11.   //constructors
  12.   public Apple () //Default
  13.   {
  14.     this.name = "undefined name";
  15.     this.weight = 0.0;
  16.     this.price = 0.0;  
  17.   }
  18.   public Apple (String aName, double aWeight, double aPrice)
  19.   {
  20.     //Get the names
  21.   }
  22.   public String getName()
  23.   {
  24.     return this.name;
  25.   }
  26.   public double getWeight ()
  27.   {
  28.    return this.weight;
  29.   }
  30.   public double getPrice()
  31.   {
  32.    return this.price;
  33.   }
  34.   //Mutators
  35.   public void setName(String aName)
  36.   {
  37.    this.name = aName;
  38.   }
  39.   public void setWeight(double aWeight)
  40.   {
  41.     if (aWeight <= 2.0 && aWeight >=0.0);
  42.     {
  43.       this.weight = aWeight;
  44.     }
  45.   }
  46.     //Other Methods
  47.   public String toString()
  48.   {
  49.     return this.name + " " + this.weight + " " + this.price;
  50.   }
  51.   public boolean equals (Apple aApple)
  52.   {
  53.     return aApple != null &&
  54.       this.name.equals(aApple.getName()) &&
  55.       this.weight == aApple.getWeight() &&
  56.       this.price == aApple.getPrice ();
  57.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement