SlideShare a Scribd company logo
BELOW IS MY CODE FOR THIS ASSIGMENT BUT IT NOT WORKING WELL PLEASE
HELP ME CORRECTTHE CODE
Implement the class and methods according to the UML and specifications below.
Part 1 - Create Product.java and ProductTest.java
The Product class models an individual item type in a vending machine. Each product has a
name, cost. and price. Note that cost is the cost of the product to the vending machine company.
Price is the price that the vending machine will charge the customer. Violet has said that she is
unwilling to deal with anything but quarters, dollar bills, and debit cards so all prices are kept
divisible by 25 cents. Costs to the vending machine company can be any penny value. All of the
get methods perform the expected operation.
Data
Note: cost and price are both integers. All money in the vending machine is represented as cents
to enable simpler math and eliminate rounding issues.
ROUND_PRICE: int - the value in cents to which all prices will be rounded
name: String - the name of the product type
cost: int
price: int
Product()
The default constructor will create an instance of a product with a name of "Generic", a cost of
ROUND_PRICE = 25 cents and a price of twice the ROUND_PRICE.
Product(String name, int cost, int price) throws IllegalArgumentException
This constructor takes the name, cost, and price as parameters and sets the instance variables
appropriately. Null string names or negative cost or price should throw an
IllegalArgumentException. Prices should be rounded to the next ROUND_PRICE cents above
the amount given if the amount given if not already divisible by ROUND_PRICE. Note: if the
price given is not greater than the cost, the price should be the next ROUND_PRICE-divisible-
value that is greater than the cost.
toString()
The toString() method will return a String of the instance variables of the class exactly as shown
below. Assuming a name of "M&Ms", cost of $1.02, and a price of $1.25, toString() would
return:
Note: the cost and price are kept in cents so the toString() method will need to transform the
values into the right format.
Part 2 - Create Slot.java and SlotTest.java
The Slot class models a slot in the vending machine. Slots are loaded from the rear, and
purchases are removed from the front. This ensures that the items that have been in the machine
the longest are sold before newly added items.
Data
SLOT_SIZE: int = 10 - the maximum number of products that a slot in the vending machine can
hold.
products: ArrayList - models the actual products that are in the slot. Removing the one at the
front models buying one of the products in the slot and all of the others are moved forward
similar to an actual vending machine.
Slot()
The Slot() constructor creates an empty array list of products.
Slot(Product product)
This constructor creates a new slot that is filled with SLOT_SIZE of product.
load(Product product)
This method loads the slot with however many new products are required to make sure it is full
and returns the number of products it took to fill the slot.
load(Product product, int count)
This method loads the slot with up to count new products in an attempt to fill the slot and returns
the number of products it used.
nextProduct()
This method returns a reference to the next product available for purchase. If the slot is empty
this method will return null.
buyOne()
This method simulates the purchase of one item from the perspective of the slot. That means no
money is dealt with here, rather the slot is checked to make sure there is product to buy and then
one product is removed from the front of the ArrayList modeling the slot. If a product is
successfully removed from the slot, it is returned, otherwise null is returned.
toString()
The toString() method returns a String exactly like the one below for a slot with 10 M&M
products. Items should start with the front slot and end with the rear slot.
Hint
Hint: Dont forget to make use of other toString() methods.
Part 3 - Create VendingMachine.java and test it.
The VendingMachine class is a simple vending machine. Exact change is required so it is
assumed if someone is buying something they have inserted the right amount of money or have
used a debit card. The get methods return the appropriate instance variable values.
Data
DEFAULT_SIZE: int = 15 the default size for a VendingMachine, used primarily by the default
constructor
totalProfit: int this models the total profit for all of the VendingMachines together. It is the sum
of the price of every product bought from all of the machines minus the sum of the cost of all the
products ever put in all of the machines. Note that it is protected in the UML diagram so it is
accessible to classes that inherit from this class.
machineProfit: int this models the long term profit for this particular machine. It is the sum of
the price of every product bought from this machine minus the sum of the cost of all the products
ever put in this machine. Note that it is protected in the UML diagram so it is accessible to
classes that inherit from this class.
slots: Slot[] this array models the array of slots in the VendingMachine.
VendingMachine()
The default constructor creates a VendingMachine with DEFAULT_SIZE empty Slots.
VendingMachine(int size)
Creates a VendingMachine with the indicated number of empty Slots.
VendingMachine(int size, Product product)
Creates a VendingMachine with size Slots each full of product.
load()
Loads an empty or partially empty VendingMachine with a Generic product (i.e. the product
obtained using the default constructor of the Product class.) Makes appropriate adjustments to
machineProfit and totalProfit by subtracting costs from profit values.
load(int slotNum, int count, Product product)throws IllegalArgumentException
Loads the slot indicated by slotNum with product until it is full or until count is reached. Makes
appropriate adjustments to machineProfit and totalProfit by subtracting costs from profit values.
Throws an IllegalArgumentException if the slotNum is out of bounds, the count is less than or
equal to zero, or if the product is null.
nextProduct(int slotNum)throws IllegalArgumentException
Returns a reference to the next available product in the indicated slot or null if the slot is empty.
Throws an IllegalArgumentException if the slotNum is out of bounds.
buy(int slotNum)throws IllegalArgumentException
Models buying one item from the slot number indicated. Makes appropriate adjustments to
machineProfit and totalProfit by adding the price to the profit values. Throws an
IllegalArgumentException if the slotNum is out of bounds. Returns false if there is no product to
buy.
resetTotalProfit()
This method resets the totalProfit static instance variable to zero. This is useful when testing to
make sure that different method tests start out in a known state for the static variable so the final
value can be computed without knowing the order of the test runs.
toString()
Returns a String representing the VendingMachine, each slot, the machineProfit and totalProfit
exactly as shown below for a 2-slot VendingMachine filled with Generic product where nothing
has been bought (so the profits are negative).
Part 4 - Create DrinkMachine.java and test it.
The drink machine inherits from the general VendingMachine described above. The only
additions are a constant for the cooling charge and a different buy method which will affect the
profit for the machine and the total profit differently than in the general VendingMachine.
DrinkMachines will assess a charge for keeping the drink cold when the drink is purchased. This
charge impacts the cost of the product to the vending machine company. It does not impact the
price for the customer.
Data
COOLING_CHARGE: int = 10 this models the ten-cent charge assessed to each drink when it is
purchased to account for the refrigeration costs of the drink machine.
DrinkMachine()
Performs the same action for the DrinkMachine as VendingMachine().
DrinkMachine(int size, Product product)
Performs the same action for the DrinkMachine as VendingMachine(int size, Product product).
buy(int slotNum) throws IllegalArgumentException
Models buying one item from the slot number indicated. Throws an IllegalArgumentException if
the slotNum is out-of-bounds. Makes appropriate adjustments to machineProfit and totalProfit by
adding the price
Hint
use a public method) minus the COOLING_CHARGE to the profit values.
Part 5 - Create ChangeMakingMachine.java and test it.
The change-making machine will add the functionality of being able to pay with cash and
potentially get change back. The change will just be returned as an integer value in cents, but the
amount paid in will be determined by the number of quarters and dollars that are entered.
ChangeMakingMachine()
Performs the same action for the ChangeMakingMachine as VendingMachine()
ChangeMakingMachine(int size)
Performs the same action for the ChangeMakingMachine as VendingMachine(int size).
ChangeMakingMachine(int size, Product product)
Performs the same action for the ChangeMakingMachine as VendingMachine(int size, Product
product)
buy(int slotNum, int quarters, int dollars)throws IllegalArgumentException
Models buying one item from the slot number indicated. Throws an IllegalArgumentException if
the slotNum is out of bounds or if quarters or dollars are negative. Computes the amount of
money put into the machine in quarters and dollars, returning -1 if there is not enough money to
buy the product and returning the positive difference or change if there is any. Makes appropriate
adjustments to machineProfit and totalProfit by adding the price to the profit values if the buy is
successful.
Note
Use a public method to accomplish this.
Part 6 - Create SnackMachine.java and test it.
The snack machine will inherit from the ChangeMakingMachine. The difference is it will have
an additional instance variable of an array list of products which will indicate the type of product
each slot should contain and its load method will fill each slot completely with the particular
product the slot contains, making appropriate adjustments to the profit tallies.
Data
productList: ArrayList contains the list of products for each slot in the SnackMachine. The first
position in the productList corresponds to the product in the first slot in the slots array.
SnackMachine(ArrayList pList)
This constructor initializes the productList of the SnackMachine and creates a new snack
machine where each slot is full of the product indicated in the matching position in the
productList. The size of the snack machine is just the length of the productList.
load()
This load method completely fills each slot in the snack machine with the appropriate product.
As a slot is filled, the total cost of the items is subtracted from the profit tallies.
Part 7 - Create Simulator.java and test it.
The simulator will provide a means of simulating a small business of vending machines. The
vending machines of the business are stored in an array list. Vending machines can be added to
the list using the provided method to simulate the growth of a business. Simulation of the
business running and selling product is done by simulating a specific number of products being
bought from every slot of every vending machine in the business and returning the totalProfit of
all of the vending machines in cents.
Data
vmList: ArrayList models the list of vending machines owned by the company
Simulator(ArrayList vmList)
Instantiates a Simulator
addVM(VendingMachine vm)
Adds the VendingMachine indicated by vm to the end of the list of vending machines owned by
the company.
simulate(int pCount)
Simulates buying pCount products from every slot of every VendingMachine owned by the
company. Returns the totalProfit of all of the VendingMachines.
public class VendingMachine {
public static final int DEFAULT_SIZE = 15;
protected static int totalProfit;
protected int machineProfit;
private Slot[] slots;
/**
* Construct a Vending Machine with default.
*/
public VendingMachine() {
this(DEFAULT_SIZE);
}
/**
* Construct a Vending Machine.
* @param size number
*/
public VendingMachine(int size) {
this.slots = new Slot[size];
for (int i = 0; i < size; i++) {
slots[i] = new Slot(new Product());
}
}
/**
* Construct a Vending Machine.
* @param size number
* @param product number
*/
public VendingMachine(int size, Product product) {
this.slots = new Slot[size];
for (int i = 0; i < size; i++) {
slots[i] = new Slot(product);
machineProfit += product.getPrice() - product.getCost();
}
totalProfit += machineProfit;
}
/**
* the method load the slots.
*
*/
public void load() {
Product product = new Product();
for (int i = 0; i < slots.length; i++) {
if (i < DEFAULT_SIZE) {
slots[i] = new Slot(new Product());
machineProfit -= product.getCost();
totalProfit -= product.getCost();
}
}
}
/**
* the method load the slots..
* @param slotNum number
* @param count number
* @param product number
*/
public void load(int slotNum, int count, Product product) throws IllegalArgumentException {
if (slotNum < 0 || slotNum >= slots.length) {
throw new IllegalArgumentException("Invalid slot number: " + slotNum);
}
if (count <= 0) {
throw new IllegalArgumentException("Count must be greater than zero: " + count);
}
if (product == null) {
throw new IllegalArgumentException("Product cannot be null.");
}
Slot slot = slots[slotNum];
int remainingCapacity = slot.load(product, count);
int actualCount = Math.min(count, remainingCapacity);
for (int i = 0; i < actualCount; i++) {
slot.nextProduct();
machineProfit -= product.getCost();
totalProfit -= product.getCost();
}
}
/**
* the method next Product.
* @param slotNum number
* @return Product
*/
public Product nextProduct(int slotNum) throws IllegalArgumentException {
if (slotNum < 0 || slotNum >= slots.length) {
throw new IllegalArgumentException("Invalid slot number: " + slotNum);
}
return slots[slotNum].nextProduct();
}
/**
* the method buy.
* @param slotNum number
* @return true
*/
public boolean buy(int slotNum) throws IllegalArgumentException {
if (slotNum < 0 || slotNum >= slots.length) {
throw new IllegalArgumentException("Invalid slot number: " + slotNum);
}
Slot slot = slots[slotNum];
Product product = slot.nextProduct();
if (product == null) {
return false;
}
machineProfit += product.getPrice() - product.getCost();
totalProfit += product.getPrice() - product.getCost();
return true;
}
/**
* the method return Slot Count.
* @return SlotCount
*/
public int getSlotCount() {
return slots.length;
}
/**
* the method get the value and return total Profit.
* @return totalProfit
*/
public static int getTotalProfit() {
return totalProfit;
}
/**
* the method reset Total Profit.
*/
public static void resetTotalProfit() {
totalProfit = 0;
}
/**
* the method get the value and return Machine Profit.
* @return getMachineProfit
*/
public int getMachineProfit() {
int cost = 0;
int price = 0;
int i = 0;
for (Slot slot : slots) {
cost += i * slot.nextProduct().getCost();
price += i * slot.nextProduct().getPrice();
i++;
}
machineProfit = price - cost;
return machineProfit;
}
/**
* the method get the value and return String.
* @return return String
*/
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Vending Machinen SlotCount: ").append(slots.length).append(" of n");
for (int i = 0; i < slots.length; i++) {
sb.append("Product: ").append(slots[i].nextProduct().getName()).append("Cost: ").
append(slots[i].nextProduct().getCost()).append("Price: ").
append(slots[i].nextProduct().getPrice()).append(".");
}
sb.append("Total Profit: ").append(totalProfit / 100.0).
append(". Machine Profit: ").append(machineProfit / 100.0).append(".");
return sb.toString();
}
}
=====================================================================
==================
public class SnackMachine extends ChangeMakingMachine {
private ArrayList productList;
private Slot[] slots;
/**
* Construct a Snack Machine.
* @param pList number
*/
public SnackMachine(ArrayList pList) {
super(pList.size());
this.productList = pList;
Product product = new Product();
for (int i = 0; i < pList.size(); i++) {
this.slots[i] = new Slot(pList.get(i));
}
this.machineProfit -= product.getCost() * pList.size();
VendingMachine.totalProfit -= product.getCost() * pList.size();
}
/**
* the method load.
*/
public void load() {
Product product = new Product();
this.machineProfit -= product.getCost() * this.productList.size();
VendingMachine.totalProfit -= product.getCost() * this.productList.size();
for (int i = 0; i < this.productList.size(); i++) {
this.slots[i] = new Slot(this.productList.get(i));
}
}
}
=======================================================
public class Simulator {
private ArrayList vmList;
/**
* Construct a Snack Machine.
* @param vmList number
*/
public Simulator(ArrayList vmList) {
this.vmList = vmList;
}
/**
* Construct a Snack Machine.
* @param vm number
*/
public void addVM(VendingMachine vm) {
vmList.add(vm);
}
/**
* the method simulate.
* @param pCount number
* @return total Profit Product
*/
public int simulate(int pCount) {
int totalProfit = 0;
for (VendingMachine vm : vmList) {
totalProfit += vm.nextProduct(pCount).getPrice();
}
return totalProfit;
}
}
=====================================================================
===
public class ChangeMakingMachine extends VendingMachine {
/**
* Construct a Change Making Machine with default.
*/
public ChangeMakingMachine() {
super();
}
/**
* Construct a Change Making Machine.
* @param size number
*/
public ChangeMakingMachine(int size) {
super(size);
}
/**
* Change Making Machine method.
* @param size number
* @param product
*
*/
public ChangeMakingMachine(int size, Product product) {
super(size, product);
}
/**
* Change Making Machine method.
* @param slotNum number
* @param quarters number
* @param dollars number
* @return int
*/
public int buy(int slotNum, int quarters, int dollars) throws IllegalArgumentException {
if (slotNum < 0 || slotNum > slotNum) {
throw new IllegalArgumentException("Invalid slot number.");
}
if (quarters < 0 || dollars < 0) {
throw new IllegalArgumentException("Invalid number of quarters or dollars.");
}
int price = nextProduct(slotNum).getPrice();
int totalPaid = 25 * quarters + 100 * dollars;
if (totalPaid < price) {
return -1;
}
int change = totalPaid - price;
return change;
}
}

More Related Content

Similar to BELOW IS MY CODE FOR THIS ASSIGMENT BUT IT NOT WORKING WELL PLEASE H.pdf

Advanced Computer Programming..pptx
Advanced Computer Programming..pptxAdvanced Computer Programming..pptx
Advanced Computer Programming..pptx
KrishanthaRanaweera1
 
Program
ProgramProgram
Program
ChrisRock22
 
Java Static Factory Methods
Java Static Factory MethodsJava Static Factory Methods
Java Static Factory Methods
Ye Win
 
Lecture 6 polymorphism
Lecture 6 polymorphismLecture 6 polymorphism
Lecture 6 polymorphism
the_wumberlog
 
OOP Assignment 03.pdf
OOP Assignment 03.pdfOOP Assignment 03.pdf
OOP Assignment 03.pdf
ARSLANMEHMOOD47
 
COIT20245, 2016 Term One - Page 1 of 9 Assessment detail.docx
COIT20245, 2016 Term One - Page 1 of 9 Assessment detail.docxCOIT20245, 2016 Term One - Page 1 of 9 Assessment detail.docx
COIT20245, 2016 Term One - Page 1 of 9 Assessment detail.docx
clarebernice
 
Automated Restaurant System (Command Design Pattern)PROBLEMY.docx
Automated Restaurant System (Command Design Pattern)PROBLEMY.docxAutomated Restaurant System (Command Design Pattern)PROBLEMY.docx
Automated Restaurant System (Command Design Pattern)PROBLEMY.docx
rock73
 
PorfolioReport
PorfolioReportPorfolioReport
PorfolioReport
Albert Chu
 
I have the first program completed (not how request, but it works) a.pdf
I have the first program completed (not how request, but it works) a.pdfI have the first program completed (not how request, but it works) a.pdf
I have the first program completed (not how request, but it works) a.pdf
footworld1
 
Super market billing system using webcam
Super market billing system using webcam Super market billing system using webcam
Super market billing system using webcam
SahithBeats
 
Goal The goal of this assignment is to help students understand the.pdf
Goal The goal of this assignment is to help students understand the.pdfGoal The goal of this assignment is to help students understand the.pdf
Goal The goal of this assignment is to help students understand the.pdf
arsmobiles
 
Vending-machine.pdf
Vending-machine.pdfVending-machine.pdf
Vending-machine.pdf
Jayaprasanna4
 
exercises_for_live_coding_Java_advanced-2.pdf
exercises_for_live_coding_Java_advanced-2.pdfexercises_for_live_coding_Java_advanced-2.pdf
exercises_for_live_coding_Java_advanced-2.pdf
enodani2008
 
Serialization Surrogates
Serialization SurrogatesSerialization Surrogates
Serialization Surrogates
Shashank Saraf
 

Similar to BELOW IS MY CODE FOR THIS ASSIGMENT BUT IT NOT WORKING WELL PLEASE H.pdf (14)

Advanced Computer Programming..pptx
Advanced Computer Programming..pptxAdvanced Computer Programming..pptx
Advanced Computer Programming..pptx
 
Program
ProgramProgram
Program
 
Java Static Factory Methods
Java Static Factory MethodsJava Static Factory Methods
Java Static Factory Methods
 
Lecture 6 polymorphism
Lecture 6 polymorphismLecture 6 polymorphism
Lecture 6 polymorphism
 
OOP Assignment 03.pdf
OOP Assignment 03.pdfOOP Assignment 03.pdf
OOP Assignment 03.pdf
 
COIT20245, 2016 Term One - Page 1 of 9 Assessment detail.docx
COIT20245, 2016 Term One - Page 1 of 9 Assessment detail.docxCOIT20245, 2016 Term One - Page 1 of 9 Assessment detail.docx
COIT20245, 2016 Term One - Page 1 of 9 Assessment detail.docx
 
Automated Restaurant System (Command Design Pattern)PROBLEMY.docx
Automated Restaurant System (Command Design Pattern)PROBLEMY.docxAutomated Restaurant System (Command Design Pattern)PROBLEMY.docx
Automated Restaurant System (Command Design Pattern)PROBLEMY.docx
 
PorfolioReport
PorfolioReportPorfolioReport
PorfolioReport
 
I have the first program completed (not how request, but it works) a.pdf
I have the first program completed (not how request, but it works) a.pdfI have the first program completed (not how request, but it works) a.pdf
I have the first program completed (not how request, but it works) a.pdf
 
Super market billing system using webcam
Super market billing system using webcam Super market billing system using webcam
Super market billing system using webcam
 
Goal The goal of this assignment is to help students understand the.pdf
Goal The goal of this assignment is to help students understand the.pdfGoal The goal of this assignment is to help students understand the.pdf
Goal The goal of this assignment is to help students understand the.pdf
 
Vending-machine.pdf
Vending-machine.pdfVending-machine.pdf
Vending-machine.pdf
 
exercises_for_live_coding_Java_advanced-2.pdf
exercises_for_live_coding_Java_advanced-2.pdfexercises_for_live_coding_Java_advanced-2.pdf
exercises_for_live_coding_Java_advanced-2.pdf
 
Serialization Surrogates
Serialization SurrogatesSerialization Surrogates
Serialization Surrogates
 

More from aminaENT

Biology Skin Color Questions1. How does high UV light affect folat.pdf
Biology Skin Color Questions1. How does high UV light affect folat.pdfBiology Skin Color Questions1. How does high UV light affect folat.pdf
Biology Skin Color Questions1. How does high UV light affect folat.pdf
aminaENT
 
Bicoid (bcd) is a maternal-effect gene in Drosophilarequired for nor.pdf
Bicoid (bcd) is a maternal-effect gene in Drosophilarequired for nor.pdfBicoid (bcd) is a maternal-effect gene in Drosophilarequired for nor.pdf
Bicoid (bcd) is a maternal-effect gene in Drosophilarequired for nor.pdf
aminaENT
 
BHP is setting up a lithium mine that costs $120 million today to op.pdf
BHP is setting up a lithium mine that costs $120 million today to op.pdfBHP is setting up a lithium mine that costs $120 million today to op.pdf
BHP is setting up a lithium mine that costs $120 million today to op.pdf
aminaENT
 
Bill Nye goes to the beach to collect data on certain types of nonli.pdf
Bill Nye goes to the beach to collect data on certain types of nonli.pdfBill Nye goes to the beach to collect data on certain types of nonli.pdf
Bill Nye goes to the beach to collect data on certain types of nonli.pdf
aminaENT
 
Bianca Genova has worked hard to make networking events for LinkedB2.pdf
Bianca Genova has worked hard to make networking events for LinkedB2.pdfBianca Genova has worked hard to make networking events for LinkedB2.pdf
Bianca Genova has worked hard to make networking events for LinkedB2.pdf
aminaENT
 
Berth Vader is a Canadian citizen who has always lived in London, On.pdf
Berth Vader is a Canadian citizen who has always lived in London, On.pdfBerth Vader is a Canadian citizen who has always lived in London, On.pdf
Berth Vader is a Canadian citizen who has always lived in London, On.pdf
aminaENT
 
Berlisle Inc. is a manufacturer of sails for small boats. The manage.pdf
Berlisle Inc. is a manufacturer of sails for small boats. The manage.pdfBerlisle Inc. is a manufacturer of sails for small boats. The manage.pdf
Berlisle Inc. is a manufacturer of sails for small boats. The manage.pdf
aminaENT
 
below you will find the condensed finacial statements for Koko Inc. .pdf
below you will find the condensed finacial statements for Koko Inc. .pdfbelow you will find the condensed finacial statements for Koko Inc. .pdf
below you will find the condensed finacial statements for Koko Inc. .pdf
aminaENT
 
Below is the January operating budget for Casey Corp., a retailer.pdf
Below is the January operating budget for Casey Corp., a retailer.pdfBelow is the January operating budget for Casey Corp., a retailer.pdf
Below is the January operating budget for Casey Corp., a retailer.pdf
aminaENT
 
Below you have the following directory structure. At the top there i.pdf
Below you have the following directory structure. At the top there i.pdfBelow you have the following directory structure. At the top there i.pdf
Below you have the following directory structure. At the top there i.pdf
aminaENT
 
Basic SEIR1. What is the equation that describes R0 for this model.pdf
Basic SEIR1. What is the equation that describes R0 for this model.pdfBasic SEIR1. What is the equation that describes R0 for this model.pdf
Basic SEIR1. What is the equation that describes R0 for this model.pdf
aminaENT
 
Be familiar with1.The main events which affected fashion ~ refer.pdf
Be familiar with1.The main events which affected fashion ~ refer.pdfBe familiar with1.The main events which affected fashion ~ refer.pdf
Be familiar with1.The main events which affected fashion ~ refer.pdf
aminaENT
 
Based on the above Project Charter and the planning meeting, develop.pdf
Based on the above Project Charter and the planning meeting, develop.pdfBased on the above Project Charter and the planning meeting, develop.pdf
Based on the above Project Charter and the planning meeting, develop.pdf
aminaENT
 
Belinda decided to adopt a Pit Bull (Buddy) to save him from being.pdf
Belinda decided to adopt a Pit Bull (Buddy) to save him from being.pdfBelinda decided to adopt a Pit Bull (Buddy) to save him from being.pdf
Belinda decided to adopt a Pit Bull (Buddy) to save him from being.pdf
aminaENT
 
Before you begin this assignment, take a moment to collect the names.pdf
Before you begin this assignment, take a moment to collect the names.pdfBefore you begin this assignment, take a moment to collect the names.pdf
Before you begin this assignment, take a moment to collect the names.pdf
aminaENT
 
Beer menu. Your twelve (12) beeralecider selections will include t.pdf
Beer menu. Your twelve (12) beeralecider selections will include t.pdfBeer menu. Your twelve (12) beeralecider selections will include t.pdf
Beer menu. Your twelve (12) beeralecider selections will include t.pdf
aminaENT
 
Broxton Group, a consumer electronics conglomerate, is reviewing.pdf
Broxton Group, a consumer electronics conglomerate, is reviewing.pdfBroxton Group, a consumer electronics conglomerate, is reviewing.pdf
Broxton Group, a consumer electronics conglomerate, is reviewing.pdf
aminaENT
 
Based on the information provided by the LEFS, I can track Toms pro.pdf
Based on the information provided by the LEFS, I can track Toms pro.pdfBased on the information provided by the LEFS, I can track Toms pro.pdf
Based on the information provided by the LEFS, I can track Toms pro.pdf
aminaENT
 
Bruce Banner was exposed to high levels of radiation (10-5 nm) durin.pdf
Bruce Banner was exposed to high levels of radiation (10-5 nm) durin.pdfBruce Banner was exposed to high levels of radiation (10-5 nm) durin.pdf
Bruce Banner was exposed to high levels of radiation (10-5 nm) durin.pdf
aminaENT
 
Briefly describe andor draw the phospolipase C-beta induction pathw.pdf
Briefly describe andor draw the phospolipase C-beta induction pathw.pdfBriefly describe andor draw the phospolipase C-beta induction pathw.pdf
Briefly describe andor draw the phospolipase C-beta induction pathw.pdf
aminaENT
 

More from aminaENT (20)

Biology Skin Color Questions1. How does high UV light affect folat.pdf
Biology Skin Color Questions1. How does high UV light affect folat.pdfBiology Skin Color Questions1. How does high UV light affect folat.pdf
Biology Skin Color Questions1. How does high UV light affect folat.pdf
 
Bicoid (bcd) is a maternal-effect gene in Drosophilarequired for nor.pdf
Bicoid (bcd) is a maternal-effect gene in Drosophilarequired for nor.pdfBicoid (bcd) is a maternal-effect gene in Drosophilarequired for nor.pdf
Bicoid (bcd) is a maternal-effect gene in Drosophilarequired for nor.pdf
 
BHP is setting up a lithium mine that costs $120 million today to op.pdf
BHP is setting up a lithium mine that costs $120 million today to op.pdfBHP is setting up a lithium mine that costs $120 million today to op.pdf
BHP is setting up a lithium mine that costs $120 million today to op.pdf
 
Bill Nye goes to the beach to collect data on certain types of nonli.pdf
Bill Nye goes to the beach to collect data on certain types of nonli.pdfBill Nye goes to the beach to collect data on certain types of nonli.pdf
Bill Nye goes to the beach to collect data on certain types of nonli.pdf
 
Bianca Genova has worked hard to make networking events for LinkedB2.pdf
Bianca Genova has worked hard to make networking events for LinkedB2.pdfBianca Genova has worked hard to make networking events for LinkedB2.pdf
Bianca Genova has worked hard to make networking events for LinkedB2.pdf
 
Berth Vader is a Canadian citizen who has always lived in London, On.pdf
Berth Vader is a Canadian citizen who has always lived in London, On.pdfBerth Vader is a Canadian citizen who has always lived in London, On.pdf
Berth Vader is a Canadian citizen who has always lived in London, On.pdf
 
Berlisle Inc. is a manufacturer of sails for small boats. The manage.pdf
Berlisle Inc. is a manufacturer of sails for small boats. The manage.pdfBerlisle Inc. is a manufacturer of sails for small boats. The manage.pdf
Berlisle Inc. is a manufacturer of sails for small boats. The manage.pdf
 
below you will find the condensed finacial statements for Koko Inc. .pdf
below you will find the condensed finacial statements for Koko Inc. .pdfbelow you will find the condensed finacial statements for Koko Inc. .pdf
below you will find the condensed finacial statements for Koko Inc. .pdf
 
Below is the January operating budget for Casey Corp., a retailer.pdf
Below is the January operating budget for Casey Corp., a retailer.pdfBelow is the January operating budget for Casey Corp., a retailer.pdf
Below is the January operating budget for Casey Corp., a retailer.pdf
 
Below you have the following directory structure. At the top there i.pdf
Below you have the following directory structure. At the top there i.pdfBelow you have the following directory structure. At the top there i.pdf
Below you have the following directory structure. At the top there i.pdf
 
Basic SEIR1. What is the equation that describes R0 for this model.pdf
Basic SEIR1. What is the equation that describes R0 for this model.pdfBasic SEIR1. What is the equation that describes R0 for this model.pdf
Basic SEIR1. What is the equation that describes R0 for this model.pdf
 
Be familiar with1.The main events which affected fashion ~ refer.pdf
Be familiar with1.The main events which affected fashion ~ refer.pdfBe familiar with1.The main events which affected fashion ~ refer.pdf
Be familiar with1.The main events which affected fashion ~ refer.pdf
 
Based on the above Project Charter and the planning meeting, develop.pdf
Based on the above Project Charter and the planning meeting, develop.pdfBased on the above Project Charter and the planning meeting, develop.pdf
Based on the above Project Charter and the planning meeting, develop.pdf
 
Belinda decided to adopt a Pit Bull (Buddy) to save him from being.pdf
Belinda decided to adopt a Pit Bull (Buddy) to save him from being.pdfBelinda decided to adopt a Pit Bull (Buddy) to save him from being.pdf
Belinda decided to adopt a Pit Bull (Buddy) to save him from being.pdf
 
Before you begin this assignment, take a moment to collect the names.pdf
Before you begin this assignment, take a moment to collect the names.pdfBefore you begin this assignment, take a moment to collect the names.pdf
Before you begin this assignment, take a moment to collect the names.pdf
 
Beer menu. Your twelve (12) beeralecider selections will include t.pdf
Beer menu. Your twelve (12) beeralecider selections will include t.pdfBeer menu. Your twelve (12) beeralecider selections will include t.pdf
Beer menu. Your twelve (12) beeralecider selections will include t.pdf
 
Broxton Group, a consumer electronics conglomerate, is reviewing.pdf
Broxton Group, a consumer electronics conglomerate, is reviewing.pdfBroxton Group, a consumer electronics conglomerate, is reviewing.pdf
Broxton Group, a consumer electronics conglomerate, is reviewing.pdf
 
Based on the information provided by the LEFS, I can track Toms pro.pdf
Based on the information provided by the LEFS, I can track Toms pro.pdfBased on the information provided by the LEFS, I can track Toms pro.pdf
Based on the information provided by the LEFS, I can track Toms pro.pdf
 
Bruce Banner was exposed to high levels of radiation (10-5 nm) durin.pdf
Bruce Banner was exposed to high levels of radiation (10-5 nm) durin.pdfBruce Banner was exposed to high levels of radiation (10-5 nm) durin.pdf
Bruce Banner was exposed to high levels of radiation (10-5 nm) durin.pdf
 
Briefly describe andor draw the phospolipase C-beta induction pathw.pdf
Briefly describe andor draw the phospolipase C-beta induction pathw.pdfBriefly describe andor draw the phospolipase C-beta induction pathw.pdf
Briefly describe andor draw the phospolipase C-beta induction pathw.pdf
 

Recently uploaded

BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
RidwanHassanYusuf
 
MDP on air pollution of class 8 year 2024-2025
MDP on air pollution of class 8 year 2024-2025MDP on air pollution of class 8 year 2024-2025
MDP on air pollution of class 8 year 2024-2025
khuleseema60
 
Contiguity Of Various Message Forms - Rupam Chandra.pptx
Contiguity Of Various Message Forms - Rupam Chandra.pptxContiguity Of Various Message Forms - Rupam Chandra.pptx
Contiguity Of Various Message Forms - Rupam Chandra.pptx
Kalna College
 
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxxSimple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
RandolphRadicy
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
سمير بسيوني
 
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
Kalna College
 
How to Setup Default Value for a Field in Odoo 17
How to Setup Default Value for a Field in Odoo 17How to Setup Default Value for a Field in Odoo 17
How to Setup Default Value for a Field in Odoo 17
Celine George
 
CIS 4200-02 Group 1 Final Project Report (1).pdf
CIS 4200-02 Group 1 Final Project Report (1).pdfCIS 4200-02 Group 1 Final Project Report (1).pdf
CIS 4200-02 Group 1 Final Project Report (1).pdf
blueshagoo1
 
BPSC-105 important questions for june term end exam
BPSC-105 important questions for june term end examBPSC-105 important questions for june term end exam
BPSC-105 important questions for june term end exam
sonukumargpnirsadhan
 
How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17
Celine George
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
MJDuyan
 
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
ImMuslim
 
The basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptxThe basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptx
heathfieldcps1
 
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdfREASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
giancarloi8888
 
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptxA Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
OH TEIK BIN
 
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
TechSoup
 
Accounting for Restricted Grants When and How To Record Properly
Accounting for Restricted Grants  When and How To Record ProperlyAccounting for Restricted Grants  When and How To Record Properly
Accounting for Restricted Grants When and How To Record Properly
TechSoup
 
Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)
nitinpv4ai
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Henry Hollis
 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
zuzanka
 

Recently uploaded (20)

BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
 
MDP on air pollution of class 8 year 2024-2025
MDP on air pollution of class 8 year 2024-2025MDP on air pollution of class 8 year 2024-2025
MDP on air pollution of class 8 year 2024-2025
 
Contiguity Of Various Message Forms - Rupam Chandra.pptx
Contiguity Of Various Message Forms - Rupam Chandra.pptxContiguity Of Various Message Forms - Rupam Chandra.pptx
Contiguity Of Various Message Forms - Rupam Chandra.pptx
 
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxxSimple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
 
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
 
How to Setup Default Value for a Field in Odoo 17
How to Setup Default Value for a Field in Odoo 17How to Setup Default Value for a Field in Odoo 17
How to Setup Default Value for a Field in Odoo 17
 
CIS 4200-02 Group 1 Final Project Report (1).pdf
CIS 4200-02 Group 1 Final Project Report (1).pdfCIS 4200-02 Group 1 Final Project Report (1).pdf
CIS 4200-02 Group 1 Final Project Report (1).pdf
 
BPSC-105 important questions for june term end exam
BPSC-105 important questions for june term end examBPSC-105 important questions for june term end exam
BPSC-105 important questions for june term end exam
 
How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
 
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
 
The basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptxThe basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptx
 
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdfREASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
 
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptxA Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
 
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
 
Accounting for Restricted Grants When and How To Record Properly
Accounting for Restricted Grants  When and How To Record ProperlyAccounting for Restricted Grants  When and How To Record Properly
Accounting for Restricted Grants When and How To Record Properly
 
Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
 

BELOW IS MY CODE FOR THIS ASSIGMENT BUT IT NOT WORKING WELL PLEASE H.pdf

  • 1. BELOW IS MY CODE FOR THIS ASSIGMENT BUT IT NOT WORKING WELL PLEASE HELP ME CORRECTTHE CODE Implement the class and methods according to the UML and specifications below. Part 1 - Create Product.java and ProductTest.java The Product class models an individual item type in a vending machine. Each product has a name, cost. and price. Note that cost is the cost of the product to the vending machine company. Price is the price that the vending machine will charge the customer. Violet has said that she is unwilling to deal with anything but quarters, dollar bills, and debit cards so all prices are kept divisible by 25 cents. Costs to the vending machine company can be any penny value. All of the get methods perform the expected operation. Data Note: cost and price are both integers. All money in the vending machine is represented as cents to enable simpler math and eliminate rounding issues. ROUND_PRICE: int - the value in cents to which all prices will be rounded name: String - the name of the product type cost: int price: int Product() The default constructor will create an instance of a product with a name of "Generic", a cost of ROUND_PRICE = 25 cents and a price of twice the ROUND_PRICE. Product(String name, int cost, int price) throws IllegalArgumentException This constructor takes the name, cost, and price as parameters and sets the instance variables appropriately. Null string names or negative cost or price should throw an IllegalArgumentException. Prices should be rounded to the next ROUND_PRICE cents above the amount given if the amount given if not already divisible by ROUND_PRICE. Note: if the price given is not greater than the cost, the price should be the next ROUND_PRICE-divisible- value that is greater than the cost. toString() The toString() method will return a String of the instance variables of the class exactly as shown below. Assuming a name of "M&Ms", cost of $1.02, and a price of $1.25, toString() would return: Note: the cost and price are kept in cents so the toString() method will need to transform the values into the right format. Part 2 - Create Slot.java and SlotTest.java The Slot class models a slot in the vending machine. Slots are loaded from the rear, and
  • 2. purchases are removed from the front. This ensures that the items that have been in the machine the longest are sold before newly added items. Data SLOT_SIZE: int = 10 - the maximum number of products that a slot in the vending machine can hold. products: ArrayList - models the actual products that are in the slot. Removing the one at the front models buying one of the products in the slot and all of the others are moved forward similar to an actual vending machine. Slot() The Slot() constructor creates an empty array list of products. Slot(Product product) This constructor creates a new slot that is filled with SLOT_SIZE of product. load(Product product) This method loads the slot with however many new products are required to make sure it is full and returns the number of products it took to fill the slot. load(Product product, int count) This method loads the slot with up to count new products in an attempt to fill the slot and returns the number of products it used. nextProduct() This method returns a reference to the next product available for purchase. If the slot is empty this method will return null. buyOne() This method simulates the purchase of one item from the perspective of the slot. That means no money is dealt with here, rather the slot is checked to make sure there is product to buy and then one product is removed from the front of the ArrayList modeling the slot. If a product is successfully removed from the slot, it is returned, otherwise null is returned. toString() The toString() method returns a String exactly like the one below for a slot with 10 M&M products. Items should start with the front slot and end with the rear slot. Hint Hint: Dont forget to make use of other toString() methods. Part 3 - Create VendingMachine.java and test it. The VendingMachine class is a simple vending machine. Exact change is required so it is assumed if someone is buying something they have inserted the right amount of money or have used a debit card. The get methods return the appropriate instance variable values. Data
  • 3. DEFAULT_SIZE: int = 15 the default size for a VendingMachine, used primarily by the default constructor totalProfit: int this models the total profit for all of the VendingMachines together. It is the sum of the price of every product bought from all of the machines minus the sum of the cost of all the products ever put in all of the machines. Note that it is protected in the UML diagram so it is accessible to classes that inherit from this class. machineProfit: int this models the long term profit for this particular machine. It is the sum of the price of every product bought from this machine minus the sum of the cost of all the products ever put in this machine. Note that it is protected in the UML diagram so it is accessible to classes that inherit from this class. slots: Slot[] this array models the array of slots in the VendingMachine. VendingMachine() The default constructor creates a VendingMachine with DEFAULT_SIZE empty Slots. VendingMachine(int size) Creates a VendingMachine with the indicated number of empty Slots. VendingMachine(int size, Product product) Creates a VendingMachine with size Slots each full of product. load() Loads an empty or partially empty VendingMachine with a Generic product (i.e. the product obtained using the default constructor of the Product class.) Makes appropriate adjustments to machineProfit and totalProfit by subtracting costs from profit values. load(int slotNum, int count, Product product)throws IllegalArgumentException Loads the slot indicated by slotNum with product until it is full or until count is reached. Makes appropriate adjustments to machineProfit and totalProfit by subtracting costs from profit values. Throws an IllegalArgumentException if the slotNum is out of bounds, the count is less than or equal to zero, or if the product is null. nextProduct(int slotNum)throws IllegalArgumentException Returns a reference to the next available product in the indicated slot or null if the slot is empty. Throws an IllegalArgumentException if the slotNum is out of bounds. buy(int slotNum)throws IllegalArgumentException Models buying one item from the slot number indicated. Makes appropriate adjustments to machineProfit and totalProfit by adding the price to the profit values. Throws an IllegalArgumentException if the slotNum is out of bounds. Returns false if there is no product to buy. resetTotalProfit() This method resets the totalProfit static instance variable to zero. This is useful when testing to
  • 4. make sure that different method tests start out in a known state for the static variable so the final value can be computed without knowing the order of the test runs. toString() Returns a String representing the VendingMachine, each slot, the machineProfit and totalProfit exactly as shown below for a 2-slot VendingMachine filled with Generic product where nothing has been bought (so the profits are negative). Part 4 - Create DrinkMachine.java and test it. The drink machine inherits from the general VendingMachine described above. The only additions are a constant for the cooling charge and a different buy method which will affect the profit for the machine and the total profit differently than in the general VendingMachine. DrinkMachines will assess a charge for keeping the drink cold when the drink is purchased. This charge impacts the cost of the product to the vending machine company. It does not impact the price for the customer. Data COOLING_CHARGE: int = 10 this models the ten-cent charge assessed to each drink when it is purchased to account for the refrigeration costs of the drink machine. DrinkMachine() Performs the same action for the DrinkMachine as VendingMachine(). DrinkMachine(int size, Product product) Performs the same action for the DrinkMachine as VendingMachine(int size, Product product). buy(int slotNum) throws IllegalArgumentException Models buying one item from the slot number indicated. Throws an IllegalArgumentException if the slotNum is out-of-bounds. Makes appropriate adjustments to machineProfit and totalProfit by adding the price Hint use a public method) minus the COOLING_CHARGE to the profit values. Part 5 - Create ChangeMakingMachine.java and test it. The change-making machine will add the functionality of being able to pay with cash and potentially get change back. The change will just be returned as an integer value in cents, but the amount paid in will be determined by the number of quarters and dollars that are entered. ChangeMakingMachine() Performs the same action for the ChangeMakingMachine as VendingMachine() ChangeMakingMachine(int size) Performs the same action for the ChangeMakingMachine as VendingMachine(int size). ChangeMakingMachine(int size, Product product) Performs the same action for the ChangeMakingMachine as VendingMachine(int size, Product
  • 5. product) buy(int slotNum, int quarters, int dollars)throws IllegalArgumentException Models buying one item from the slot number indicated. Throws an IllegalArgumentException if the slotNum is out of bounds or if quarters or dollars are negative. Computes the amount of money put into the machine in quarters and dollars, returning -1 if there is not enough money to buy the product and returning the positive difference or change if there is any. Makes appropriate adjustments to machineProfit and totalProfit by adding the price to the profit values if the buy is successful. Note Use a public method to accomplish this. Part 6 - Create SnackMachine.java and test it. The snack machine will inherit from the ChangeMakingMachine. The difference is it will have an additional instance variable of an array list of products which will indicate the type of product each slot should contain and its load method will fill each slot completely with the particular product the slot contains, making appropriate adjustments to the profit tallies. Data productList: ArrayList contains the list of products for each slot in the SnackMachine. The first position in the productList corresponds to the product in the first slot in the slots array. SnackMachine(ArrayList pList) This constructor initializes the productList of the SnackMachine and creates a new snack machine where each slot is full of the product indicated in the matching position in the productList. The size of the snack machine is just the length of the productList. load() This load method completely fills each slot in the snack machine with the appropriate product. As a slot is filled, the total cost of the items is subtracted from the profit tallies. Part 7 - Create Simulator.java and test it. The simulator will provide a means of simulating a small business of vending machines. The vending machines of the business are stored in an array list. Vending machines can be added to the list using the provided method to simulate the growth of a business. Simulation of the business running and selling product is done by simulating a specific number of products being bought from every slot of every vending machine in the business and returning the totalProfit of all of the vending machines in cents. Data vmList: ArrayList models the list of vending machines owned by the company Simulator(ArrayList vmList) Instantiates a Simulator
  • 6. addVM(VendingMachine vm) Adds the VendingMachine indicated by vm to the end of the list of vending machines owned by the company. simulate(int pCount) Simulates buying pCount products from every slot of every VendingMachine owned by the company. Returns the totalProfit of all of the VendingMachines. public class VendingMachine { public static final int DEFAULT_SIZE = 15; protected static int totalProfit; protected int machineProfit; private Slot[] slots; /** * Construct a Vending Machine with default. */ public VendingMachine() { this(DEFAULT_SIZE); } /** * Construct a Vending Machine. * @param size number */ public VendingMachine(int size) { this.slots = new Slot[size]; for (int i = 0; i < size; i++) { slots[i] = new Slot(new Product()); } } /** * Construct a Vending Machine. * @param size number * @param product number */
  • 7. public VendingMachine(int size, Product product) { this.slots = new Slot[size]; for (int i = 0; i < size; i++) { slots[i] = new Slot(product); machineProfit += product.getPrice() - product.getCost(); } totalProfit += machineProfit; } /** * the method load the slots. * */ public void load() { Product product = new Product(); for (int i = 0; i < slots.length; i++) { if (i < DEFAULT_SIZE) { slots[i] = new Slot(new Product()); machineProfit -= product.getCost(); totalProfit -= product.getCost(); } } } /** * the method load the slots.. * @param slotNum number * @param count number * @param product number */ public void load(int slotNum, int count, Product product) throws IllegalArgumentException { if (slotNum < 0 || slotNum >= slots.length) { throw new IllegalArgumentException("Invalid slot number: " + slotNum); } if (count <= 0) {
  • 8. throw new IllegalArgumentException("Count must be greater than zero: " + count); } if (product == null) { throw new IllegalArgumentException("Product cannot be null."); } Slot slot = slots[slotNum]; int remainingCapacity = slot.load(product, count); int actualCount = Math.min(count, remainingCapacity); for (int i = 0; i < actualCount; i++) { slot.nextProduct(); machineProfit -= product.getCost(); totalProfit -= product.getCost(); } } /** * the method next Product. * @param slotNum number * @return Product */ public Product nextProduct(int slotNum) throws IllegalArgumentException { if (slotNum < 0 || slotNum >= slots.length) { throw new IllegalArgumentException("Invalid slot number: " + slotNum); } return slots[slotNum].nextProduct(); } /** * the method buy. * @param slotNum number * @return true */ public boolean buy(int slotNum) throws IllegalArgumentException { if (slotNum < 0 || slotNum >= slots.length) { throw new IllegalArgumentException("Invalid slot number: " + slotNum); }
  • 9. Slot slot = slots[slotNum]; Product product = slot.nextProduct(); if (product == null) { return false; } machineProfit += product.getPrice() - product.getCost(); totalProfit += product.getPrice() - product.getCost(); return true; } /** * the method return Slot Count. * @return SlotCount */ public int getSlotCount() { return slots.length; } /** * the method get the value and return total Profit. * @return totalProfit */ public static int getTotalProfit() { return totalProfit; } /** * the method reset Total Profit. */ public static void resetTotalProfit() { totalProfit = 0; } /**
  • 10. * the method get the value and return Machine Profit. * @return getMachineProfit */ public int getMachineProfit() { int cost = 0; int price = 0; int i = 0; for (Slot slot : slots) { cost += i * slot.nextProduct().getCost(); price += i * slot.nextProduct().getPrice(); i++; } machineProfit = price - cost; return machineProfit; } /** * the method get the value and return String. * @return return String */ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("Vending Machinen SlotCount: ").append(slots.length).append(" of n"); for (int i = 0; i < slots.length; i++) { sb.append("Product: ").append(slots[i].nextProduct().getName()).append("Cost: "). append(slots[i].nextProduct().getCost()).append("Price: "). append(slots[i].nextProduct().getPrice()).append("."); } sb.append("Total Profit: ").append(totalProfit / 100.0). append(". Machine Profit: ").append(machineProfit / 100.0).append("."); return sb.toString(); } } =====================================================================
  • 11. ================== public class SnackMachine extends ChangeMakingMachine { private ArrayList productList; private Slot[] slots; /** * Construct a Snack Machine. * @param pList number */ public SnackMachine(ArrayList pList) { super(pList.size()); this.productList = pList; Product product = new Product(); for (int i = 0; i < pList.size(); i++) { this.slots[i] = new Slot(pList.get(i)); } this.machineProfit -= product.getCost() * pList.size(); VendingMachine.totalProfit -= product.getCost() * pList.size(); } /** * the method load. */ public void load() { Product product = new Product(); this.machineProfit -= product.getCost() * this.productList.size(); VendingMachine.totalProfit -= product.getCost() * this.productList.size(); for (int i = 0; i < this.productList.size(); i++) { this.slots[i] = new Slot(this.productList.get(i)); } } } ======================================================= public class Simulator { private ArrayList vmList; /**
  • 12. * Construct a Snack Machine. * @param vmList number */ public Simulator(ArrayList vmList) { this.vmList = vmList; } /** * Construct a Snack Machine. * @param vm number */ public void addVM(VendingMachine vm) { vmList.add(vm); } /** * the method simulate. * @param pCount number * @return total Profit Product */ public int simulate(int pCount) { int totalProfit = 0; for (VendingMachine vm : vmList) { totalProfit += vm.nextProduct(pCount).getPrice(); } return totalProfit; } } ===================================================================== === public class ChangeMakingMachine extends VendingMachine { /** * Construct a Change Making Machine with default. */ public ChangeMakingMachine() {
  • 13. super(); } /** * Construct a Change Making Machine. * @param size number */ public ChangeMakingMachine(int size) { super(size); } /** * Change Making Machine method. * @param size number * @param product * */ public ChangeMakingMachine(int size, Product product) { super(size, product); } /** * Change Making Machine method. * @param slotNum number * @param quarters number * @param dollars number * @return int */ public int buy(int slotNum, int quarters, int dollars) throws IllegalArgumentException { if (slotNum < 0 || slotNum > slotNum) { throw new IllegalArgumentException("Invalid slot number."); } if (quarters < 0 || dollars < 0) { throw new IllegalArgumentException("Invalid number of quarters or dollars."); }
  • 14. int price = nextProduct(slotNum).getPrice(); int totalPaid = 25 * quarters + 100 * dollars; if (totalPaid < price) { return -1; } int change = totalPaid - price; return change; } }