Vending Machine Program - Inheritance In Java

Mar 24, 2015

I'm making a vending machine program to practice inheritance and have a few questions. My superclass is a Soda class, and I'm making subclasses like "Orange soda", "Coke", etc. My first question is, what is the point of the subclass inheriting the instance variables of the superclass? If you have to define them again is there any point in the super class having them? Here is an example of this:

My superclass:

public abstract class Soda {

public double price;
public int numAvailable;
public String name;
public String machineCode;

[code]...

Besides not having to write the vendSoda() method again, what is the benefit of inheritance in a situation like this if you have to define all variables again? My second question is, how could I store all of the code strings from all of the different subclasses in one place? (so when the user enters a code it can search for the code entered to give the desired soda)...

View Replies


ADVERTISEMENT

Simple Vending Machine Program

Jan 22, 2014

I am having a difficult time writing what started out as a simple vending machine program. As I go on though, it seems that I'm overcomplicating it and it is getting messy, so I have resorted to the forum before I really get off the path. how to clean it up? I'm going to list a few of the problems I am having with the code below:

1. The user is supposed to enter his/her money and the program is to read each value separately (Do-While loop) and keep a running total of the money entered. I can't seem to get the right code format to do this. I was trying to do this with the variable total and so that is why the total exists in the switch statement, but it did not work.

2. In the second Do-While statement, is there a way to kick back an error when their are insufficient funds to purchase an item? Instead of getting a negative change return.

package practice;
import java.util.Scanner;
public class Practice {
public static void main(String[] args) {
double count, total;
int item;
//Display Available Options To Customer
Scanner input = new Scanner(System.in);
System.out.println("*VENDING MACHINE*");

[code]....

View Replies View Related

Vending Machine - Different Files

May 1, 2014

keep getting an error when inventory is printed out. wont carry the money over. cant find out how to do it?

[import java.util.Scanner;
public class VMachine
{
Scanner input = new Scanner (System.in);
double candy;
double soda;
double dsoda;
double money;

[Code] ....

View Replies View Related

Vending Machine Algorithm - Item Order And Retrieval

Oct 18, 2014

I'm having a major problem in forming the algorithm for my JAVA project, which is a vending machine. I desperately need one in order for it to guide me in making the code. I plan to include an array, switch class to customer and technician portals, item order and retrieval, and change calculator.

View Replies View Related

Making Vending Machine - Asking User To Insert More Money

Sep 23, 2014

So I am making a vending machine and am having trouble knowing what exactly to use or how to go about giving the user a error message depending if they initially added enough money for their choice of drink. So if the user only input 1 dollar, and the drink they select is $1.25, they need to add the $.25, but how do I implement that in this code?

Here is my code along with the zip file just in case.

package vending.sample;
import java.util.Scanner;
public class VendingSample {
public static void main(String[] args) {
int coke = 1, sprite = 2, DrPepper = 3, Pepsi = 4, Fanta = 5, Water = 6, selection, i;
double change, total;

[Code] ....

View Replies View Related

Vending Machine - Tell User Combination Of Coins That Equals To Amount Of Change

Jan 25, 2012

I have a simple java program to write which tells the user combination of coins that equals to the amount of change i.e:

user input 87

output:

3 quarters
1 dime
0 nickels
2 pennies

How the program remembers the remainder which is passed to the next column of let say dime

i.e

originalAmount = amount;
quarters = amount /25;
amount = amount % 25; <---- this is confusing for me?!?! how can the integer = integer % 25
dimes = amount / 10; <--- HOW THE PROGRAM remembers the "remainder" instead of the original user input as the code it self tells you dimes = amount where "amount" is what user input NOT remainder.

amount = amount % 10;
so on ....;

What I don't understand is HOW this algorithm works. I mean we have int amount where user inputs the number we get the first calculation amount/25 = how many quarters and then amount %25 WILL tell us about the reminder. By looking at this piece of code I would say that the system should start the calculation for the dimes again from the original number since the code says dimes = amount/10 AND amount = amount%10. My understanding is that the calculation should be done from the original user input.

Book or code it self is not clear for me how the reminder is "REMEMBERED" and then pass on to the next calculation>!?!?

UNLESS the code: amount=amount%25 gets the remainder so the next code under it is REQUIRED to read from the last prompt code.

View Replies View Related

Java Code To Access Windows Machine From Unix Machine

Feb 28, 2014

I have a requirement where I have to send a file from a local system to unix box(present on client side) using java code.I have developed a code that is successfully sending the file from local system to client side unix box (I am connecting to client side unix box using VPN) provided I run the code in my eclipse IDE present in local system. But when I am running the same code in the unix box it is throwing null pointer exception.Might be the unix system is not recognising the local system. Please find the code.
 
package abc;
import java.io.File;
import java.io.FileInputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.Properties;
import com.jcraft.jsch.Channel;

[Code] ....

Error on unix box which I am getting is :-
 
Inside sftpConnection method
llllllll
fffffffffffff
Connection Successfull
Channel Connection Succesfull
aaaaa
Inside findFile method
Exception in thread "main" java.lang.NullPointerException
        at abc.TranferFile.sftpConnection(TranferFile.java:58)
        at abc.TranferFile.main(TranferFile.java:21)

View Replies View Related

Networking :: Connecting To Remote Windows Machine From Local Machine Using SSH2

Apr 11, 2014

I have developed a code to connecting remote windows M/C from local M/C by using SSH2 (ganymed-ssh2-build209.jar) API. when I run the code its giving below error. Is there any other way to connect remote windows system using java code.
 
Exception.
 
java.io.IOException: There was a problem while talking to <host name>:22
  at ch.ethz.ssh2.Connection.connect(Connection.java:642)
  at ch.ethz.ssh2.Connection.connect(Connection.java:460)
  at Connect.RemoteServer.ConnectWindowsServer.runCommand(ConnectWindowsServer.java:55)
  at Connect.RemoteServer.ConnectWindowsServer.main(ConnectWindowsServer.java:27)
Caused by: java.net.ConnectException: Connection refused: connect

[Code] ....
 
JAVA Code

import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.Session;
 public void setAuthenticationInfo(String hostname, String username,String password) {
       this.host = hostname;
       this.userid = username;
       this.password = password;      
       this.recentCommand = "";     
       System.out.println("setting authentication info completed for host=" + host );
 
[Code] .....

View Replies View Related

Writing A Program To Make A Tic Tac Toe Game Utilizing Inheritance

May 7, 2014

I am new to programming and we are writing a program to make a tic tac toe game utilizing inheritance, client-supplier, arrays, and EventButton. I am still trying to wrap my head around events and inheritance. We are instructed to write 4 classes (a TicTacToeModel, a TicTacToeView, a TicTacToe Controller, and a TicTacToeButton). I got the TicTacToeModel down, but am having trouble with the other classes.

Instructions for View: Write a class that implements the UML class diagram below. The only purpose of this class is to draw a picture of the specified TicTacToeModel. For purposes of this assignment, we understand a ‘theme’ to include such things as the background color of the tic‐tac‐toe board, the shape and color of the X indicator and the shape and color of the O indicator. While you are free to select your own personalized ‘theme’ your TicTacToeComponent must always be proportionally ‘correct’ regardless of the client‐determined width and height of the Component.

Instructions for the Controller: Write a controller that controls the game. There is one human player (the X player) and the computer player (the O player). The name of the class must be TicTacToeController. In a sense, the controller is the game since the controller will

1) create a TicTacToeModel
2) create a TicTacToeView and
3) create a TicTacToeButton (you must write this class following the design pattern covered in class lectures), a label, and text field such that when the button is pushed, the player moves into the cell selected by the text field. After every player move, the computer moves into a randomly selected empty cell. When the game is over, a text message must be displayed somewhere on the screen the gives the status of the game. While you are free to change the appearance of the controller, the basic elements must be provided

These are our instructions for the TicTacToeButton: create a TicTacToeButton (you must write this class following the design pattern covered in class lectures), a label, and text field such that when the button is pushed, the player moves into the cell selected by the text field. After every player move, the computer moves into a randomly selected empty cell. When the game is over, a text message must be displayed somewhere on the screen the gives the status of the game.And this is the code I have thus far for the button:

import java.awt.event.*;
import java.awt.*;
public class TicTacToeButton extends EventButton{
public TicTacToeButton(int x, int y, int w, int h) {
super("Move");
setBounds(x, y, w, h);

[code]....

View Replies View Related

Program Which Stimulates A Bet Placer Machine

Dec 23, 2014

I am making a program which stimulates a bet placer machine for horse race betting for my school project.The program isnt complete yet but till this it doesnt let me input the String a and the program stops after printing "Type "view info" to display info about the different derbies". I use BlueJ 3.1.0 and version of jdk is the latest Java 8 Update 25

import java.util.*;
public class Derby
{
public static void main()
{
Scanner in=new Scanner(System.in);
System.out.println("Welcome to the Horse Racing Bet Placer Machine");
System.out.println("Through this Machine you can place bets on different derbies accross the globe");
System.out.println("Press 1 to choose a Derby"); //Ask user whether he wants to place a bet or not
System.out.println("Press 2 if you don't want to place a bet");
int choice=in.nextInt(); //Inputs user's choice
if (choice==2) //Determines the user's choice

[code]....

In this screenshot, after printing ''Type "view info" to display info about the different derbies'' it should let me input the value of String a according to the code but instead it stops the program there and doesn't let me input anything

View Replies View Related

Slot Machine Program Using Methods And Arrays

Nov 13, 2014

I am designing a program that generates 3 random numbers from 1-5 and if 2 match, the user wins $1. If 3 match, the user wins respectively:

All 1s - $5
2s - $10
3s - $25
4s - $50
5s - $100

I first used a loop to run until the user runs out of money or wishes to stop. Then I made 2 methods. 1 to generate the random numbers and 1 to see if the user won any money. I am storing the random numbers in an array called slotnumber.

This is what I have so far but I am getting compiling errors at while (cont == 'y') {

import java.util.Scanner;
import java.util.Random;
public class SlotMachine
{

[Code]......

View Replies View Related

Running Program From Server On Client Machine

Aug 9, 2014

I had some questions about a theoretical java program. Say you had a java program on a linux server/pc that referenced a folder on that server. And say you had a Client PC (Windows) that had a share folder to that java program.

If that windows client PC tried to run the program would it run (with a GUI if it had one) and would the main directory of the java program still be on the linux server or would it be on the windows computer since that is the computer that is running the program?

Basically I have a program I am trying to find the best way to run it remotely on a windows computer but it references files on the linux server it is located at and needs to put files it creates there as well. I am just trying to make sure I understand my theory here on how the program will run if it IS run remotely.

View Replies View Related

Methods And Arrays Slot Machine Program Won't Compile

Nov 19, 2014

Here are the errors I am getting:

SlotMachine.java:21: error: illegal start of expression
public static void getNums(int [] slots)
^
SlotMachine.java:21: error: illegal start of expression
public static void getNums(int [] slots)

[code]....

i keep fixing small things and cannot get it to compile. Below is the original code,

import java.util.Scanner;
import java.util.Random;
public class SlotMachine
{
public static void main (String args[]) {
int userMoney;
Scanner input = new Scanner(System.in);
System.out.print("How much money to start with?

[code]....

View Replies View Related

Implementing Inheritance In Java

Apr 25, 2014

i was leaning inheritance and tried to implement it in Java.This is my base class vehicl.java

public class vehicle{
private int topSpeed;
private int cubicCap;
private String modelName;
private boolean hasAlloy;

[code]...

I also have a derived class called car.java.What i wanted to do in the derived class was that i wanted to override the constructor as well as the getInfo() method from the base class.I wanted to add an additional attribute to the car "numberSeats" and display tat too when the object to car class calls the getInfo() method .It showed an error "identifier required" when i tried to compile car.java program.

import java.util.Scanner;
public class car extends vehicle{
//int numberSeats;
//System.out.println("Enter the number of Seats");
Scanner numberSeats=new Scanner(System.in);
numberSeats=numberSeats.nextInt();
//System.out.println(numberSeats.nextInt());

[code]....

explain the errors that i get when i tried to compile car.java without using super keyword or without defining the constructor from the Car class ?

View Replies View Related

Java Serialization With Inheritance And Aggregation

Feb 20, 2015

What is difference between Java Serialization with Inheritance (IS-A Relationship) and Java Serialization with Aggregation (HAS-A Relationship) ....

View Replies View Related

How Multiple Inheritance Is Possible In Java With Interfaces

Apr 11, 2014

This is my assignment.

Identify how multiple inheritance is possible in Java with interfaces.

Write a java programme with appropriate classes to demonstrate the above.

Hint: both inheritance and interface concepts are necessary.

For the project name in netbeans, use your id and the name "assignment" separated by underscore,

E.g. 9876543_assignment

View Replies View Related

Implement Multiple Inheritance In Java Using Interfaces?

Jan 12, 2014

how can i implement multiple inheritance in java using interfaces. if interfaces have some methods having same name then how to distinguish that ?

View Replies View Related

How To Do Multiple Inheritance Without Single Interface In Java

Apr 3, 2014

how to do multiple inheritance without sing interface in java?

View Replies View Related

Java Does Not Support Multiple Inheritance Using Classes

Aug 16, 2014

I studied that java does not support multiple inheritance using classes. It is fine practically, but I have still a question in mind:Lets see the below code.

class Test{
------
------
}

class MyTest extends Test{
---------
---------
}

Here, as we know that that Object is Super class for every class in java. and I have already extends a Test class in MyTest.My question is: How is it possible to extend features of two class at the same time?

Theoretically,

MyTest extends Object &
MyTest extends Test.

View Replies View Related

What Is Java Virtual Machine

Mar 5, 2014

What is Java Virtual Machine (Java VM)?

View Replies View Related

Could Not Create The Java Virtual Machine

Dec 11, 2014

I keep getting this error:-
/opt/solr# java -v
Unrecognized option: -v
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

View Replies View Related

Could Not Create Java Virtual Machine

Jan 19, 2012

Since a few weeks i receive windows reports with the text: "Could not create the Java virtual machine". That were not disturbing, but now i would like to play a game that based on Java, but every time I would start it, the message come and the game do not start. The game called "Edna and Harvey: The Breakout" (German: Edna bricht aus) and is developed by a german game studio called "Daedalic entertainment".

View Replies View Related

Java Virtual Machine Launcher

May 1, 2015

I created a program and am able to run it perfectly fine in netbeans/cmd. Then I made an .exe file with "Launch4j" and every time that I run the .exe file I get the following error: Java Virtual Machine Launcher: "A Java Exception has occurred."

Here in detail:

Exception in thread "main" java.lang.NoClassDefFoundError: edu/cmu/sphinx/util/props/PropertyException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)

[code]...

View Replies View Related

Java - Connection With Time Attendance Machine In Network

Apr 15, 2015

I'm working in project, my theme is to develop an application management system for fingerprint and RFID card attendance machine in java programming language.

My problem i didn't find documentation in java for connecting with this device.

View Replies View Related

Virtual Machine Launcher - Java Exception Has Occurred

Apr 29, 2014

I developed a Java application and it works fine on my computer, but when i tried it on another computers, I have the following errors :

A window named Java Virtual Machine Launcher appears and it says "A Java Exception has occured".

My application don't even launch.

Here is the error lines, but I don't know what to do :

C:UsersAdministrateur_localserveurtimet>java -jar ServeurTimeT.jar
Exception in thread "main" java.lang.UnsupportedClassVersionError: TimeTracking/
ServeurTimeT : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)

[Code] ....

Java is up to date.

View Replies View Related

Getting UnknownHostException While Executing Java Class In Linux Machine

Oct 16, 2014

Find the error log here ......

[pccbuildmgr@svl-jbuild-d1 Logical_Versioning]$ java -jar VersionUpdate1.jar

Picked up _JAVA_OPTIONS: -Xmx10g -XX:MaxPermSize=10g

can get the values for 1.0

java.net.UnknownHostException: home
at java.net.PlainSocketImpl.connect(PlainSocketImpl.j ava:195)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.j ava:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)

[Code] ....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved