Starting from:
$30

$24

CS Assignment#2: Vending Machine Solved

Goal

Create your first ADT (the Shelf). Gain familiarity with the interfaces, generics and classes.

Introduction

University of Pittsburgh is trying to spearhead the vending machine market by developing specialized vending machines for college campuses. The first models will be placed in the Posvar Hall and Sennot Square, and are catered specifically to computer scientists. Since you have experience with the student body, you have been tasked with writing the software. However, University of Pittsburgh wants to make sure that their product will be an overwhelming success. For that reason, you will first write a simulator for the machine to test the functionality.














Problem Description

You will be writing classes that represent various parts of a vending machine. You will need to write two files: Shelf.java and VendingItem.java. A simple driver class VendingPittClient.java has been pro-vided, and it will allow you to interact with your simulation within the commandline/terminal. Specific instructions for each file are given in later sections.

Solution Description


VendingItem:

Your VendingItem class implements VendingItemInterface and it should have the following fields, met-hods, and constructors:

private final double price. This field is the price of an item, and should be set in the constructor. private final String name. This field is the name of an item, and should be set in the constructor.

VendingItem(double price, String name). This is the constructor and it takes the price and the name as parameters.

***You need to implement all the methods described in the provided interface (VendingItemInter-face.java).***

Shelf<T>:

This class represents the vending machine itself and is the bulk of the assignment. It implements ShelfIn-terface<T> and it has the following fields, methods, and constructors:

1
public Shelf(int rows, int columns, int quantity). This is the a constructor with three parameters. You should initialize your fields and create the shelf here so that your vending machine is ready to use as soon as someone initializes it.

private T[][][] shelf. This a 3D array of generic items represents how the items are arranged in the vending machine. shelf[i][j][k] represents the item located in the ith row, jth column, and kth position where position 0 (shelf[i][j][0]) is the item at the front of the stack and each subsequent position represents the item behind it. The shelf should be initialized using a constructor(public Shelf(int rows, int columns, int quantity)).

private final int rows. Variable for holding the number of rows. This should be initialize during the constructor.

private final int columns. Variable for holding the number of rows. This should be initialize during the constructor.

private final int quantity. Variable for holding the number of rows. This should be initialize during the constructor.

***You need to implement all the methods described in the provided interface (ShelfInterface.java).***

Running and Testing

VendingPittClient.java has been provided for you. It creates two instances of VendingMachine, and allows the user to interact with them. You can run the main method to start a simulation, and test from there. The tester may not cover all cases, so be sure to write your own code to test your simulation.

Academic Honesty

The work in this assignment is to be done independently. Discussions with other students on the assig-nment should be limited to understanding the statement of the problem. Cheating in any way, including giving your work to someone else will result in an F for the course and a report to the appropriate Uni-versity authority.

What to submit

Upload all your java files (preferably is a .zip) using the website. If you overwrite the provided in-terfaces, remember to restore them to their original versions. All programs will be tested on the com-mand line, so if you use an IDE to develop your program, you must export the java files from the IDE and ensure that they compile and run on the command line. Do not submit the IDE’s project fi-les. Your TA should be able to compile and run your code as discussed in Lab 1. For instance, javac edu/pitt/cs/as1/VendingPittClient.java and java edu.pitt.cs.as1.VendingPittClient must compile and run VendingPittClient.

In addition to your code, you may wish to include a README.txt file that describes features of your program that are not working as expected, to assist the TA in grading the portions that do work as expected.

How to submit your assignment

We will use a Web-based assignment submission interface. To submit your assignment:

Go to the class web page http://db.cs.pitt.edu/courses/cs0445/current.term/ and click the Submit button.

Use your pittID/username as the username and your PeopleSoft ID as the password for authentica-tion. There is a reminder service via email if you forgot your PeopleSoft ID.

Upload your assignment file(s) to the appropriate assignment (from the drop-down list).




2
Check (through the web interface) to verify what is the file size that has been uploaded and make sure it has been submitted in full. It is your responsibility to make sure the assignment was properly submitted.

You must submit your assignment before the due date (8:00 PM, Monday, Sept 30, 2019). There are no late submissions.



























































3

More products