Question

If your program does not compile, you will not receive any points! You will write a program to keep up with a Jewelry...

If your program does not compile, you will not receive any points!

You will write a program to keep up with a Jewelry store and some of the Inventory (rings/necklaces/earrings) purchased there (The Jewelry store can be real or not) using Object-Oriented Programming (OOP). The important aspect of object-oriented programming is modular development and testing of reusable software modules.

You love selling rings, necklaces, and earrings as well as programming and have decided to open a Jewelry store. To save money you will write your own program to keep up with your inventory and store.

You will need the five classes discussed below:

- An Inventory class, with class attributes of a product type (ring/necklace/or earrings), a description (kind of metal/jewel etc.), and a cost (this is a monetary value). Make sure these variables are safe (inaccessible from outside of this class)
** about the description: The description should be about what the item is made with/of. I.E. Ring: Diamond Promise ring in 10K Rose Gold. NOT ring: mood ring

- A Test_Inventory class, that is a Junit test class for the Inventory class. This should contain at least 7 test methods testing the Constructors (1 for each variable in the non-empty Constructor) and setters.

- You will need a JewelryStore class, with class attributes of your JewelryStore’s name, an Array (size of 10) of Inventory sold at the JewelryStore, and a counter to keep track of how many items are in the array.

- A Test_JewelryStore class, that is a Junit test class for the JewelryStore class. This should contain at least 6 times est methods, again testing the Constructors, setter, and add method (1 for each variable in the method).

- Your P1Driver has a class attribute of a JewelryStore (DO NOT instantiate any Inventory objects in this class). All the data for the JewelryStore and Inventory are to be hard coded (Do Not ask the user for that data) and passed to the appropriate methods.

Your program will need to:
  

- The Junit tests for the two classes should pass.
- Hard code the data for the JewelryStore and Inventory in the
P1Driver.
- Print a welcoming message for your JewelryStore
- Print the name of your JewelryStore and all the Inventory (you must
have at least 6 different kinds of Inventory, 2 of each type, for the JewelryStore), including the Inventory type, description, and cost (be sure to have different costs, don’t make them all $130.00 or something dumb like that), as well as how much inventory your store has.
- Calculate and print the average cost of Inventory sold at the JewelryStore. Be sure that this average cost looks like a normal monetary amount (i.e.: $245.75 and not $245.75425)
- Print a Good-Bye or Thank you message.
1 0
Add a comment Improve this question Transcribed image text
Answer #1

############## Inventory.java ###############

/**
* The Class Inventory.
*/
public class Inventory {

   /** The product type. */
   private String productType;
  
   /** The description. */
   private String description;
  
   /** The cost. */
   private double cost;

   /**
   * Instantiates a new inventory.
   *
   * @param productType the product type
   * @param description the description
   * @param cost the cost
   */
   public Inventory(String productType, String description, double cost) {
       this.productType = productType;
       this.description = description;
       this.cost = cost;
   }

   /**
   * Instantiates a new inventory.
   */
   public Inventory() {
       // default constructor
   }

   /**
   * Gets the product type.
   *
   * @return the productType
   */
   public String getProductType() {
       return productType;
   }

   /**
   * Sets the product type.
   *
   * @param productType the productType to set
   */
   public void setProductType(String productType) {
       this.productType = productType;
   }

   /**
   * Gets the description.
   *
   * @return the description
   */
   public String getDescription() {
       return description;
   }

   /**
   * Sets the description.
   *
   * @param description the description to set
   */
   public void setDescription(String description) {
       this.description = description;
   }

   /**
   * Gets the cost.
   *
   * @return the cost
   */
   public double getCost() {
       return cost;
   }

   /**
   * Sets the cost.
   *
   * @param cost the cost to set
   */
   public void setCost(double cost) {
       this.cost = cost;
   }

   @Override
   public String toString() {
       return String.format("Product Type: %s, Description: %s, Cost: $%.2f", productType, description, cost);
   }

}

################## Test_Inventory.java ##############

import static org.junit.Assert.assertEquals;

import org.junit.Test;

/**
* The Class Test_Inventory.
*/
public class Test_Inventory {
  
   /**
   * The main method.
   *
   * @param args the arguments
   */
   public static void main(String[] args) {
       org.junit.runner.JUnitCore.main("Test_Inventory");
   }

   /**
   * Constructor test 1.
   */
   @Test
   public void constructorTest1() {
       Inventory inventory = new Inventory("Ring", null, 0);
       assertEquals("Ring", inventory.getProductType());
   }

   /**
   * Constructor test 2.
   */
   @Test
   public void constructorTest2() {
       Inventory inventory = new Inventory(null, "Ring: Diamond Promise ring in 10K Rose Gold. NOT ring: mood ring", 0);
       assertEquals("Ring: Diamond Promise ring in 10K Rose Gold. NOT ring: mood ring", inventory.getDescription());
   }

   /**
   * Constructor test 3.
   */
   @Test
   public void constructorTest3() {
       Inventory inventory = new Inventory(null, null, 253.53);
       assertEquals("253.53", String.valueOf(inventory.getCost()));
   }

  
   /**
   * Setter test 1.
   */
   @Test
   public void setterTest1() {
       Inventory inventory = new Inventory();
       inventory.setProductType("Ring");
       assertEquals("Ring", inventory.getProductType());
   }

   /**
   * Setter test 2.
   */
   @Test
   public void setterTest2() {
       Inventory inventory = new Inventory();
       inventory.setDescription("Ring: Diamond Promise ring in 10K Rose Gold. NOT ring: mood ring");
       assertEquals("Ring: Diamond Promise ring in 10K Rose Gold. NOT ring: mood ring", inventory.getDescription());
   }

   /**
   * Setter test 3.
   */
   @Test
   public void setterTest3() {
       Inventory inventory = new Inventory();
       inventory.setCost(253.53);
       assertEquals("253.53", String.valueOf(inventory.getCost()));
   }
  
   /**
   * To string test.
   */
   @Test
   public void toStringTest() {
       Inventory inventory = new Inventory("Ring", "Ring: Diamond Promise ring in 10K Rose Gold. NOT ring: mood ring", 253.53);
       String m = inventory.toString();
       assertEquals("Product Type: Ring, Description: Ring: Diamond Promise ring in 10K Rose Gold. NOT ring: mood ring, Cost: $253.53", m);
   }

}

################# JewelleryStore.java ##############
/**
* The Class JewelleryStore.
*/
public class JewelleryStore {

   /** The store name. */
   private String storeName;
  
   /** The inventory sold. */
   private Inventory[] inventorySold;
  
   /** The items sold. */
   private int itemsSold;

   /**
   * Instantiates a new jewellery store.
   */
   public JewelleryStore() {
       this.inventorySold = new Inventory[10];
       this.itemsSold = 0;
   }

   /**
   * Instantiates a new jewellery store.
   *
   * @param storeName the store name
   */
   public JewelleryStore(String storeName) {
       this.inventorySold = new Inventory[10];
       this.storeName = storeName;
       this.itemsSold = 0;
   }

   /**
   * Gets the store name.
   *
   * @return the storeName
   */
   public String getStoreName() {
       return storeName;
   }

   /**
   * Sets the store name.
   *
   * @param storeName the storeName to set
   */
   public void setStoreName(String storeName) {
       this.storeName = storeName;
   }

   /**
   * Gets the inventory sold.
   *
   * @return the inventorySold
   */
   public Inventory[] getInventorySold() {
       return inventorySold;
   }

   /**
   * Sets the inventory sold.
   *
   * @param inventorySold the inventorySold to set
   */
   public void setInventorySold(Inventory[] inventorySold) {
       this.inventorySold = inventorySold;
   }

   /**
   * Gets the items sold.
   *
   * @return the itemsSold
   */
   public int getItemsSold() {
       return itemsSold;
   }

   /**
   * Sets the items sold.
   *
   * @param itemsSold the itemsSold to set
   */
   public void setItemsSold(int itemsSold) {
       this.itemsSold = itemsSold;
   }

   /**
   * Adds the.
   *
   * @param inventory the inventory
   */
   public void add(Inventory inventory) {
       this.inventorySold[itemsSold++] = inventory;
   }

   @Override
   public String toString() {
       return String.format("StoreName: %s, ItemsSold: %d", storeName, itemsSold);
   }

}
################# Test_JewelleryStore.java ################
import static org.junit.Assert.assertEquals;

import org.junit.Test;

/**
* The Class Test_JewelleryStore.
*/
public class Test_JewelleryStore {

   /**
   * The main method.
   *
   * @param args the arguments
   */
   public static void main(String[] args) {
       org.junit.runner.JUnitCore.main("Test_JewelleryStore");
   }

   /**
   * Constructor test 1.
   */
   @Test
   public void constructorTest1() {
       JewelleryStore jewelleryStore = new JewelleryStore("BB Jewellers");
       assertEquals("BB Jewellers", jewelleryStore.getStoreName());
   }

   /**
   * Setter test 1.
   */
   @Test
   public void setterTest1() {
       JewelleryStore jewelleryStore = new JewelleryStore();
       jewelleryStore.setStoreName("BB Jewellers");
       assertEquals("BB Jewellers", jewelleryStore.getStoreName());
   }

   /**
   * Setter test 2.
   */
   @Test
   public void setterTest2() {
       JewelleryStore jewelleryStore = new JewelleryStore();
       Inventory[] inventory = {new Inventory("Ring", "Ring: Diamond Promise ring in 10K Rose Gold. NOT ring: mood ring", 253.53)};
       jewelleryStore.setInventorySold(inventory);
       assertEquals("Ring", jewelleryStore.getInventorySold()[0].getProductType());
   }

   /**
   * Setter test 3.
   */
   @Test
   public void setterTest3() {
       JewelleryStore jewelleryStore = new JewelleryStore();
       jewelleryStore.setItemsSold(2);
       assertEquals("2", String.valueOf(jewelleryStore.getItemsSold()));
   }
  
  
   /**
   * Adds the test.
   */
   @Test
   public void addTest() {
       JewelleryStore jewelleryStore = new JewelleryStore();
       Inventory inventory = new Inventory("Ring", "Ring: Diamond Promise ring in 10K Rose Gold. NOT ring: mood ring", 253.53);
       jewelleryStore.add(inventory);
       assertEquals("1", String.valueOf(jewelleryStore.getItemsSold()));
   }
  
   /**
   * To string test.
   */
   @Test
   public void toStringTest() {
       JewelleryStore jewelleryStore = new JewelleryStore("BB Jewellers");
       Inventory inventory = new Inventory("Ring", "Ring: Diamond Promise ring in 10K Rose Gold. NOT ring: mood ring", 253.53);
       jewelleryStore.add(inventory);
       String m = jewelleryStore.toString();
       assertEquals("StoreName: BB Jewellers, ItemsSold: 1", m);
   }
  
}

################# P1Driver.java ###################

/**
* The Class P1Driver.
*/
public class P1Driver {

   /**
   * The main method.
   *
   * @param args the arguments
   */
   public static void main(String[] args) {
       JewelleryStore jewelleryStore = new JewelleryStore("BB Jewellers");
       Inventory inventory1 = new Inventory("Ring", "Ring: Diamond Promise ring in 10K Rose Gold. NOT ring: mood ring", 253.53);
       Inventory inventory2 = new Inventory("Necklace", "Necklace: Pure Diamond", 1000.23);
       Inventory inventory3 = new Inventory("Braclet", "Braclet: Made of borzen and allow", 36.20);
       Inventory inventory4 = new Inventory("Anklet", "Anklet: Silver coated", 13.00);
       Inventory inventory5 = new Inventory("Bangal", "Bangal:23 cart pure gold", 40.88);
       Inventory inventory6 = new Inventory("Chain", "Chain: 23 cart pure gold", 743.13);
       jewelleryStore.add(inventory1);
       jewelleryStore.add(inventory2);
       jewelleryStore.add(inventory3);
       jewelleryStore.add(inventory4);
       jewelleryStore.add(inventory5);
       jewelleryStore.add(inventory6);

       System.out.println("Welome to " + jewelleryStore.getStoreName());
       System.out.println(jewelleryStore.getStoreName());
       for (Inventory inventory : jewelleryStore.getInventorySold()) {
           if (inventory != null) {
               System.out.println(inventory.toString());
           }
       }
      
       System.out.println("Thank you message");
   }
}

«terminated> IDriver (1) Java A lication] C:\Program Files Ja ayre180 וכ bin ava exe May 2019, T3 :20 PM) elome to BB Jewelle

Add a comment
Know the answer?
Add Answer to:
If your program does not compile, you will not receive any points! You will write a program to keep up with a Jewelry...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Here is a sample run of the tester program: Make sure your program follows the Java...

    Here is a sample run of the tester program: Make sure your program follows the Java Coding Guidelines. Consider the following class: /** * A store superclass with a Name and Sales Tax Rate */ public class Store {      public final double SALES_TAX_RATE = 0.06;      private String name;           /**      * Constructor to create a new store      * @param newName      */      public Store(String newName)      {           name = newName;      }     ...

  • Order up:: Write a program that will be used to keep track of orders placed at...

    Order up:: Write a program that will be used to keep track of orders placed at a donut shop. There are two types of items that can be ordered: coffee or donuts. Your program will have a class for each order type, and an abstract superclass. Coffee orders are constructed with the following information: quantity (int) - how many coffees are being ordered size (String) - the size of the coffees (all coffees in the order have the same size)...

  • Need this program in C#. Thank you 3/19 Lab11 PartC Dur Scenario/Summary Write a windows console...

    Need this program in C#. Thank you 3/19 Lab11 PartC Dur Scenario/Summary Write a windows console application that holds data about an item in a retail store. Your class should be named Retailltem and should hold data about an item in a retail store. The class will have the following member variables. Description- string holding the description of the item, unitsOnHand - int that holds the number of units in inventory Price - double that holds the price of the...

  • In C++ Write a program that contains a BankAccount class. The BankAccount class should store the...

    In C++ Write a program that contains a BankAccount class. The BankAccount class should store the following attributes: account name account balance Make sure you use the correct access modifiers for the variables. Write get/set methods for all attributes. Write a constructor that takes two parameters. Write a default constructor. Write a method called Deposit(double) that adds the passed in amount to the balance. Write a method called Withdraw(double) that subtracts the passed in amount from the balance. Do not...

  • Create the Python code for a program adhering to the following specifications. Write an Employee class...

    Create the Python code for a program adhering to the following specifications. Write an Employee class that keeps data attributes for the following pieces of information: - Employee Name (a string) - Employee Number (a string) Make sure to create all the accessor, mutator, and __str__ methods for the object. Next, write a class named ProductionWorker that is a subclass of the Employee class. The ProductionWorker class should keep data attributes for the following information: - Shift number (an integer,...

  • When answering this question, can you please specify what you name your files? Thank you! Write a...

    When answering this question, can you please specify what you name your files? Thank you! Write a Java application, and an additional class to represent some real-world entity. Keep in mind that a class is a model in code of something real or imagined, which has attributes (member variables) and behaviors (member methods). The class will: a. Create a total of 5 member variables for the class, selecting the appropriate data types for each field. For example, a class to...

  • M01 PA C++ Classes and Objects INTRODUCTION: Write a C++ program that implements and utilizes a...

    M01 PA C++ Classes and Objects INTRODUCTION: Write a C++ program that implements and utilizes a Stereo Receiver Class/Object. INCLUDE IN YOUR ASSIGNMENT At the top of each of your C++ programs, you should have at least four lines of documentation: Program name (the C++ file name(s)), Author (your name), Date last updated, and Purpose (a brief description of what the program accomplishes). Here is an example: // Program name: tictactoe.cpp // Author: Rainbow Dash // Date last updated: 5/26/2016...

  • C++ Simple code please Thank you in advance B. Write a C++ program as per the...

    C++ Simple code please Thank you in advance B. Write a C++ program as per the following specifications: a. Define the class BankAccount to store a bank customer's account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. Add appropriate constructors. b. Every bank...

  • Write a program to subtract large unsigned integers. Your program should prompt and read in two...

    Write a program to subtract large unsigned integers. Your program should prompt and read in two large unsigned integers. The two large integers should be stored arrays, one array for each integer. The integers should be stored with one digit per location in the two arrays. The first integer should be no smaller than the second. Your program should subtract the second integer from the first. The result should be stored in an array, again one digit per location in...

  • Week 6: Lab Overview TABLE OF CONTENTS Lab Overview Scenario/Summary Write a windows console application that...

    Week 6: Lab Overview TABLE OF CONTENTS Lab Overview Scenario/Summary Write a windows console application that holds data about an item in a retail store. Your class should be named RetailItem and should hold data about an item in a retail store. The class will have the following member variables. Description - string holding the description of the item, unitsOnHand - int that holds the number of units in inventory Price - double that holds the price of the item...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT