Pages

Total Pageviews

Sunday, June 16, 2019

Lab 10 Exercise Questions at Java Programming

class Item Class {
   private String description;
   private int quantity;
   private double price;
   public Item(String description, int quantity, double price)
   {
      this.description = description;
      this.price = price;
      this.quantity = quantity;
   }
   public Item(String description, double price)
   {
      this.description = description;
      this.price = price;
      this.quantity = 0;
   }
   public String getDescription()
   {
      return description;
   }
   public void setDescription(String description)
   {
      this.description = description;
   }
   public double getPrice()
   {
      return price;
   }
   public void setPrice(double price)
   {
      this.price = price;
   }
   public int getQuantity()
   {
      return quantity;
   }
   public void setQuantity(int quantity)
   {
      this.quantity = quantity;
   }
}

class Item Driver
{
   public static void main(String[] args)
   {
      System.out.println("Welcome to Store Management Program");

      Item spoon, fork, knife, dish, bowl;
      spoon = new Item("Spoon", 14, 1.25);
      fork = new Item("Fork", 18, 1.50);
      knife = new Item("Knife", 2, 2.35);
      dish = new Item("Dish", 5.95);
      bowl = new Item("Bowl", 4.99);
     
      fork.setPrice(1.75);
      dish.setQuantity(5);
      bowl.setQuantity(8);
      knife.setDescription("Butter Knife");
     
      Item[] items = new Item[5];
      items[0] = spoon;
      items[1] = fork;
      items[2] = knife;
      items[3] = dish;
      items[4] = bowl;
     
     
      for(int i = 0; i < items.length; i++)
      {
         Item item = items[i];
         System.out.println("We have "+item.getQuantity()+" "+item.getDescription()+" (s) at a price of $"+item.getPrice()+" each");
      }     
      System.out.println("Thanks for using my program!");
   }
}


class Item {

   private String description;
   private int quantity;
   private double price;
   public Item(String description, int quantity, double price)
   {
      this.description = description;
      this.price = price;
      this.quantity = quantity;
   }
   public Item(String description, double price)
   {
      this.description = description;
      this.price = price;
      this.quantity = 0;
   }
   public String getDescription()
   {
      return description;
   }
   public void setDescription(String description)
   {
      this.description = description;
   }
   public double getPrice()
   {
      return price;
   }
   public void setPrice(double price)
   {
      this.price = price;
   }
   public int getQuantity()
   {
      return quantity;
   }
   public void setQuantity(int quantity)
   {
      this.quantity = quantity;
   }
}




http://erdoganakbiyik.blogspot.com/
https://www.youtube.com/channel/UCDsUnmBfVdEPkcC8FlzPKcg

No comments:

Post a Comment