Homework help--almost done but don't know how my class and main work?
hello, i'm doing a project for my intro to java class. i'm almost done but i'm very confused on making my main and class work. the counter for my class slotMachine keeps resetting after 2 increments. also i don't not know how to make my quarters in the main receive a pay out from my class. Please guide me to understand what i have to do to solve this problem...I have listed my question page and my class and main of what i have done so far. Thank you .I will really appreciate the help.
Objective: Create a class in Java, make instances of that class. Call methods that solve a particular problem Consider the difference between procedural and object-oriented programming for the same problem.
Program Purpose:
Find out how long it will take Martha to lose all of her money playing 3 instances of the slot machine class.
Specification: Martha in Vegas
Martha takes a jar of quarters to the casino with the intention of becoming rich. She plays three machines in turn. Unknown to her, the machines are entirely predictable. Each play costs one quarter. The first machine pays 30 quarters every 35th time it is played; the second machine pays 60 quarters every 100th time it is played; the third pays 11 quarters every 10th time it is played. (If she played the 3rd machine only she would be a winner.)
Your program should take as input the number of quarters in Martha's jar (there will be at least one and fewer than 1000), and the number of times each machine has been played since it last paid.
Your program should output the number of times Martha plays until she goes broke.
Sample Session. User input is in italics
How many quarters does Martha have in the jar?
48
How many times has the first machine been played since playing out?
30
How many times has the second machine been played since paying out?
10
How many times has the third machine been played since paying out?
9
Martha plays XXX times
Specific requirements: You must solve this using an object-oriented approach. Create a class called SlotMachine. Think about: What does a SlotMachine Have? What does it do? What information does it maintain? This is the state and behavior of the object. Each instance of this class will represent a single slot machine. Don�t put anything in the class unless it �belongs� to a single machine.
In the main method, create 3 instances of the slot machine to solve the problem in the spec. Play the machines in a loop.
========================================================================
my class
========================================================================
public class SlotMachine{
private int payOut;
private int playLimit;
private int counter;
public SlotMachine (int payOut, int playLimit){
this.payOut = payOut;
this.playLimit = playLimit;
public void setPayOut (int payOut){
this.payOut = payOut;
public int getPayOut(){
return payOut;
public void setPlayLimit (int playLimit){
this.playLimit = playLimit;
public int getPlayLimit(){
return playLimit;
public void slotCounter(){
counter = SavitchIn.readLineInt();
public int game(){
counter++;
if (counter == playLimit){
counter = 0;
return payOut - 1;
return -1; // the game method was edited by my professor but i'm still confused to make it work
=======================================================================
my main
=======================================================================
public class Gametesting{
public static void main(String[]args){
SlotMachine firstSlotMachine = new SlotMachine (2,3);
SlotMachine secondSlotMachine = new SlotMachine (2,3);
SlotMachine thirdSlotMachine = new SlotMachine (2,2);
int quarters;
int playerCount = 0;
System.out.println("How many quarters does Martha have in the jar?");
quarters = SavitchIn.readLineInt();
System.out.println("How many times has the first machine been played since paying out?");
firstSlotMachine.slotCounter();
System.out.println("How many times has the second machine been played since paying out?");
secondSlotMachine.slotCounter();
System.out.println("How many times has the third machine been played since paying out?");
thirdSlotMachine.slotCounter();
while (quarters != 0){
playerCount++;
quarters--;
firstSlotMachine.game();
if (quarters != 0){
playerCount++;
quarters--;
secondSlotMachine.game();
if (quarters != 0){
playerCount++;
quarters--;
thirdSlotMachine.game();
System.out.println("Martha plays " + playerCount + " times");
The main problem is that you made the first and second slot machine to pay out 2 quarters after 3 games and the third machine pay out two quarters after two games. That is not what your assignment specified.
SlotMachine firstSlotMachine = new SlotMachine (2,3);
SlotMachine secondSlotMachine = new SlotMachine (2,3);
SlotMachine thirdSlotMachine = new SlotMachine (2,2);
The second problem is that you never add the payout of a machine to Martha's number of quarters.
Look carefully at the way your professor implemented the game() method. If you think about it, what it returns is the net "gain" from playing a game. On jackpot it returns payOut -1 (jackpot less the one quarter Martha had to pay for the game), otherwise it returns -1 (Martha spends one quarter and wins nothing).
So what you can do is simply add the returned value to the number of quarters in the jar -
quarters = <machine>.game();
instead of quarters--.
Similar Messages
-
I am selling my apple mac pro but do not know how to deregister and register it to the new owner; how do you do this?
Before you sell or give away your computer, in addition to the steps mentioned in this support article, take these steps:
Run Apple Diagnostics or the Apple Hardware Test. The buyer will do this (or he should), and you don't want to be surprised by the results.
Reset the PRAM and the SMC, which might contain personal information.
If you set a firmware password, remove it by running Firmware Password Utility in Recovery mode.
If you activated FileVault in OS X 10.7 or later, turn it off.
If you use Boot Camp, the partition must be deleted
If you created any other data partitions on the internal drive, remove them in Disk Utility.
Erase the data partition(s) with the option to zero out data. An SSD doesn't need to be zeroed.
You can't legally or practically transfer any software downloaded from the Mac App Store to the new owner of the machine, even if it was free. That includes OS X, so if you upgraded to OS X 10.7 or later, you must reinstall an older OS, either from the installation media, if applicable, or by booting into Internet Recovery (option-command-R at the startup chime.) If you installed from physical media, deliver those to the new owner.
If you're selling the machine, or donating it in working order, and it originally shipped with OS X 10.4 or 10.5, then you have the option of installing either from the discs that came with it or from a retail Snow Leopard disc (which you must then transfer with the machine.) The buyer should understand that if he doesn't get the original discs from you, he won't get the bundled iLife applications or the Apple Hardware Test. Replacements for the original discs can be ordered from Apple.
The new owner will have to redownload any software that came from the App Store, including OS X upgrades, under his or her Apple ID. If you ever updated the bundled iLife applications (Garage Band, iMovie, and iPhoto) through the App Store, you can't transfer those either.
Remove the machine from your list of registered products. If it's still covered by an AppleCare Protection Plan, transfer the coverage to the new owner by following the instructions in the AppleCare Terms and Conditions (under the heading "Transfer of Plan.") -
I Have a samsung smart TV and use TVO to record free to air programmes .
i would like to purchase from iTunes using my iPad , a TV series called outlander but do not know how to transfer and save the episodes to my TIVO
please helpMany videos in the iTunes store are protected so that they can only be viewed on Apple Devices signed into your iTunes account. If that is the case then your TiVo will not be able to read the files. If you know how to get a video file onto your TiVo from a flash drive, then just plug a flash drive into your Mac and drag one of the videos from inside the iTunes window onto the icon for the flash drive on your Desktop or in the left sidebar of a Finder window. That will copy the actual file onto the flash drive.
-
how do i set up my 3g sim for my iPad? the sim is already activated but i dont know how to get it to work
Setting>Cellular Data>On
-
iTunes wont open for me. it keeps saying "the Disc "untitled playlist" cannot be read. An unknown error occurred (-69)." don't know how to get it to work. Please help
It is likely a hardware failure
http://support.apple.com/kb/TS3694?viewlocale=en_US#error1 -
My I phone 4 G home page i cons are twice the size as normal (mail, messages, ipod) etc.
Don't know how this happened and can't fix it help.Double tap with THREE fingers to turn zoom off. Then go into: Settings>General>Accessibility and turn it off for good.
-
Hi People!
Please help...I want to know how can i get photos from ipad to the computer, that were synchronized previously to ipad but from another pc that i dont have access anymore and these pics are now only found in this ipad and no other place.Hi Alan,
Thanks for the help, but i've actually done that before.
It does not help, because it only shows the photos on the camera roll and do not show the photos synchronized with that pc that i dont have access anymore.
The photos/albums all appear on the ipad, i can see it without problems but i cant get them out of the ipad to save onto pc for backup.
And i reaaly need it, as it is the only place that i actually have these photos now... -
My MacBook Pro is running VERY slowly. After reading other questions and responses, I ran an EtreCheck, but do not know how to post the report here. Any help would be greatly appreciated.
My MacBook Pro is running VERY slowly. After reading other questions and responses, I ran an EtreCheck, but do not know how to post the report here. Any help would be greatly appreciated.
-
how do you get your ipod touch to make a noise when people text you and to pop up on the screen my friend did something to her ipod to do this but i dont know how please help!!!!!!!!!!!!!!!!!!!!!!!!!!! its like she updated it but i already tried it!!!!!!i am very confused and want my ipod touch 4g like that please help thxns:)
Go to Settings>Notifications and turn alerts/sounds on for the app(s) in question. Not all apps have all options.
-
After upgrading my software i have seem to have lost all my contacts and photos, i did a back up but i have no idea how to get them back on? maybe im illiterate but i dont know how to find it in my itunes? please help!!
http://support.apple.com/kb/HT5824?viewlocale=en_US&locale=en_US
-
please help me try to contact the owner of this phone IMEI **** ICCID **** i got his phone now with me but i dont know how to contact them first time i got it low battery contact me
I will explan more how i got this phone
Call me +**** Micky Thai
<Personal Information Edited By Host>A long shot but you might try using the phone to send an email to the phone asking the owner to call their mobile phone. If the owner has a computer they may get the email and get in contact with you.
But Roger's suggerstion of turning it over to the police is the best bet.
OT -
I pre-ordered an album and i did not get it! i payed 14 some dollars for it and never received it i checked to see if i bought it and it said i did. i looked to see if i could re download the album but i dont know how please help!
If you are in a country where music can be redownloaded then it should show in the Purchased tab in the iTunes store app on your phone, and the Purchased link under Quicklinks on the right-hand side of the iTunes store homepage on your computer's iTunes. If it doesn't show there then does the Store > Check For Available Downloads menu option on your computer's iTunes find it ?
-
I bought an ipod shuffle 2nd gen a few years back. i did try to set it up at the time but found it hard (i was young and impatient!!) got bored and never tried again. I really would love to start using it now, but i dont know how....please help!!!
Hello emmalemonjuice,
Why not take a look and make use of your iPod's User Guide?
http://manuals.info.apple.com/en_US/iPod_shuffle_Features_Guide.pdf
B-rock -
How to pair an i5 to my lexus, the car has a code of 1111, but I dont know how to pair it to my phone, can anyone help ?
From the iPhone User Manual:
Pairing Bluetooth devices
Before you can use a Bluetooth device with iPhone, you must first pair them.
Pair a Bluetooth device with iPhone:
1 Make the device discoverable.
See the documentation that came with the device. For an Apple Wireless Keyboard, press the On/off switch.
2 Go to Settings > Bluetooth and turn Bluetooth on.
3 Select the device and, if prompted, enter the passkey or PIN. See the instructions about the passkey or PIN that came with the device. For information about using an Apple Wireless Keyboard, see Apple Wireless Keyboard on page 24.
To use a Bluetooth headset with iPhone, see the documentation that came with the device.
Return audio output to iPhone when a Bluetooth headset is connected: Turn off or unpair the device, or turn off Bluetooth in Settings > Bluetooth. Audio output returns to iPhone whenever the device is out of range. You can also use AirPlay to switch audio output to iPhone. See AirPlay on page 30. -
on my 3gs keep getting error message charging not supported with this accessory even when its not plugged in and i have done a restore anyone know how to fix
Clean the iPhone charging port with a clean dry toothbrush.
Maybe you are looking for
-
Dell 2400MP projector and mini-DisplayPort
I have a MacBook Pro with a mini-DisplayPort and wanted to know which mini-DisplayPort to VGA adapter should I get to connect to the Dell 2400MP? It only has a VGA port, and I'm doing a presentation at a place that uses such a projector, and wanted t
-
How to extract files from external server
Dear Friends, I need to connect to an external non SAP server, from which i need to extract invoice files. Invoice files are of two types: 1. .dat format files which contain invoice data 2. .PDF or .JPEG documents, which are supporting documents for
-
Hey Guys, There are a few related questions here. Let's start here: 1. I have an add on I wrote for my company and it loads and works great on previous versions of Firefox but just stopped working with Firefox 4. Now with the latest version it seems
-
24' 2.16ghz video issues and freezing w 10.5
I was running 10.5.x - I honestly forget where it was at version wise but it was fully updated as of Thursday the 25th of Feb. and I was getting many random horizontal "rainbow" lines in Safari (also updated to that day) and also the machine would to
-
Hi, I have to migrate windows 2003 CA setup to win 2012 set up. I have NDES installed on one of the Sub CA which will be used for Airwatch MDM integration. I have received new request for using NDES for BYOD configuration on CISCo ISE, pls refer to b