473,473 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Vending machine program

22 New Member
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 14809
Ganon11
3,652 Recognized Expert Specialist
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
JohnSmith70
22 New Member
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 MVP
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 Recognized Expert MVP
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
JohnSmith70
22 New Member
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 MVP
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 Recognized Expert MVP
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
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.