473,386 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Vending machine program

Please help I need help with this homework.

Its about vending machines, and it should be a piece of cake to you code experts out there.

Its about vending machines. Heres the question:

It should have two classes, one for the vending machine(VM) and the other for drinks. The capacity of the VM is specified on creation. The drinks can be added after this. VM just created should have no drinks. These drinks are stored in slots and are numbered. Only these specified coins can be accepted: 10, 50 cents and 1 dollar. VM should have no coins when created. The VM should let the user know how much the VM currently has and should be displayed as e.g. $1.05. The VM should allow the user to be able to abort and the VM should refund the money if it has not given any drinks. The VM should display what coins will be used for the refund. This program should not allow runtime errors.

Please note that the answer to this should be very simple and basic as we have covered only the very basic stuff, since this is only an introductory course. The answer will be of no use to me if it isn't solved in a basic manner.

Thanks in advance. I really appreciate any assistance available as I'm afraid I'll fail the course. Whats upsetting is that we have not been prepared enough to solve such a question, yet we are being asked.

Regards,

John
Oct 30 '07 #1
7 14800
Ganon11
3,652 Expert 2GB
The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

Please read the Posting Guidelines and particularly the Coursework Posting Guidelines.

Then when you are ready post a new question in this thread.

MODERATOR
Oct 30 '07 #2
Can you at least help me out a little. So it starts with probably class name:

public class VM
{
public VM()
{
vendingMachnine[];
}

public double[] coins = {};
public final String[] vM= {"Pepsi","Fanta","Diet Coke"};
}

Then what? How can I learn if I don't have similar examples.
Oct 30 '07 #3
r035198x
13,262 8TB
Can you at least help me out a little. So it starts with probably class name:

public class VM
{
public VM()
{
vendingMachnine[];
}

public double[] coins = {};
public final String[] vM= {"Pepsi","Fanta","Diet Coke"};
}

Then what? How can I learn if I don't have similar examples.
1.) Please use code tags when posting code.
2.) Your specs say "The capacity of the VM is specified on creation". Where have you specified this in your class? You should refer to your specs every time you are not sure about what to do next.
Oct 30 '07 #4
JosAH
11,448 Expert 8TB
The following two remarks really amaze me; no kidding.

The answer will be of no use to me if it isn't solved in a basic manner.

Then what? How can I learn if I don't have similar examples.
Here are a few hints: measure the amount of money in pennies, so instead
of thinking in $1.05 think of 105 pennies. You can use ints for monetary amounts
then. The brand of a drink is coupled to a selling price, so the Drink class can
be as simple as this:

Expand|Select|Wrap|Line Numbers
  1. public class Drink {
  2.    private String brand;
  3.    private int money;
  4.    public Drink(String brand, int money) {
  5.       this.brand= brand;
  6.       this.money= money;
  7.    }
  8.    // two getters should be here
  9.    // and may an equals() and hashCode() method
  10. }
  11.  
Note that this class is a complete 'bean' class. The vending machine should
contain some form of container that can store Drinks. The actual container is
up to you. I'd use a Map for it that associates a brand of Drinks with the number
of cans present in the vending machine but feel free to use a simple array and
add utitility functionality around that array (e.g. is Cola Light still available? etc.)

Next, realize that the vending machine is a state machine, i.e. there are only
a couple of states which determine what the machine can and should do given
a certain state.

Examples of states are: reset state, enough money supplied state, non enough
money supplied state, return change of money after dispensing a can. return all
money and back to the reset state etc. etc.

This forum will certainly *not* do your homework for you; I guess the hints I gave
you above will get you started in a more sensible way.

kind regards,

Jos
Oct 30 '07 #5
Hi,

Thanks for helping get started guys. I guess I got a little panicked, but I've been able to make some progress. Now though I'm stuck and was wondering if you could help me out.

I'm using a multiple array for this vending machine program. Though I'm not sure. Should one dimensional array be enough. Also, with this program the user should be able to buy the drink by selecting its slot number. So how do I write the code so that I can specifiy with the index number of the array to be outputted, or simply allow it to be bought. Basically I'm trying to make an input and the output should be the content of the array at the specified index number.

Expand|Select|Wrap|Line Numbers
  1. for (int i = 0; i < array.length; i++) {           
  2.  
  3. }               
  4.  
  5.  
Can someone please help me out.

Regards,

John
Nov 1 '07 #6
r035198x
13,262 8TB
Hi,

Thanks for helping get started guys. I guess I got a little panicked, but I've been able to make some progress. Now though I'm stuck and was wondering if you could help me out.

I'm using a multiple array for this vending machine program. Though I'm not sure. Should one dimensional array be enough. Also, with this program the user should be able to buy the drink by selecting its slot number. So how do I write the code so that I can specifiy with the index number of the array to be outputted, or simply allow it to be bought. Basically I'm trying to make an input and the output should be the content of the array at the specified index number.

Expand|Select|Wrap|Line Numbers
  1. for (int i = 0; i < array.length; i++) {           
  2.  
  3. }               
  4.  
  5.  
Can someone please help me out.

Regards,

John
Why don't you start by writing the classes required and fulfiling their specifications?
Nov 1 '07 #7
JosAH
11,448 Expert 8TB
Hi,

Thanks for helping get started guys. I guess I got a little panicked, but I've been able to make some progress. Now though I'm stuck and was wondering if you could help me out.

I'm using a multiple array for this vending machine program. Though I'm not sure. Should one dimensional array be enough. Also, with this program the user should be able to buy the drink by selecting its slot number. So how do I write the code so that I can specifiy with the index number of the array to be outputted, or simply allow it to be bought. Basically I'm trying to make an input and the output should be the content of the array at the specified index number.

Expand|Select|Wrap|Line Numbers
  1. for (int i = 0; i < array.length; i++) {           
  2.  
  3. }               
  4.  
  5.  
Can someone please help me out.

Regards,

John
You could use the little class I sketched in my previous reply (with a couple of
modifications):

Expand|Select|Wrap|Line Numbers
  1. public class Drink {
  2.    private String brand;
  3.    private int money;
  4.    private int stock;
  5.    public Drink(String brand, int money, int stock) {
  6.       this.brand= brand;
  7.       this.money= money;
  8.       this.stock= stock;
  9.    }
  10.    // three getters and a few setters should be here
  11.    // and may an equals() and hashCode() method
  12. }
  13.  
The vending machine could simply use an array of Drinks then:

Expand|Select|Wrap|Line Numbers
  1. public class VendingMachine {
  2.  
  3.    private Drink[] drinks;
  4.  
  5.    // a machine with 'nofDrinks' slots
  6.    public VendingMachine(int nofDrinks) {
  7.       drinks= new Drink[nofDrinks];
  8.    }
  9.    // setters here to put stock in the vending machine
  10.    // getters here to inspect the stock
  11. }
  12.  
kind regards,

Jos
Nov 2 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: pradeepkumar | last post by:
give me the code for vending machine in c++. it has 10 items in a .first display all the items and its cost and its quantityonhand.then ask the customer if he wishes to buy.if yes tell him to select...
0
by: joestevens232 | last post by:
I am seriously stuck and have been working on this for hours and hours and can't figure out my next step....heres the program assignment. This vending machine dispenses 1. M&Ms ($.65), 2. Chips...
9
by: vpascuzzi | last post by:
Here's the deal: I've been working on this little program forever now, and can't seem to get the final little glitches out of it. I am to build a vending machine, using 2 header .h files (one...
2
by: nb999 | last post by:
Hello Friends, I was trying to simulate a vending machine using perl just as a fun project. Heres the code I wrote: #!/usr/bin/perl $wt = $ARGV;
1
by: Kunthea | last post by:
I am not that good at programming and I need a little push on how I can start my programming on the vending machine. The basic of the homework is that it displays four snacks and corresponding...
3
by: ismaeel | last post by:
i very need for intrfase of vending machine for netbense sending to email plese
1
by: abil | last post by:
i've already build a program that contain all the price, the change given back to the customer but i dun have no idea which function i should use to do program print report... #include <cstdlib>...
3
by: exospire | last post by:
Hello everyone, I made a program that simulates a vending machine for class. I finally got it to execute without any errors, yet something is not right. I have functions that are being called upon...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.