Hello everybody,
slot machine exercise that has been done for college.
Source Code: Slot Machine - Google Drive
Regards
slot machine exercise that has been done for college.
Source Code: Slot Machine - Google Drive
Regards
|
Java
Slot Machine |
|
Hello everybody,
slot machine exercise that has been done for college. Source Code: Slot Machine - Google Drive Regards
Oct 26, 2019 08:37 AM
(This post was last modified: Oct 26, 2019 08:47 AM by MavenGradle.)
Holy shit Nemo2478 , You're still using JDK 1.7? Allow me to introduce you to 2019:
https://adoptopenjdk.net/?variant=openjd...nt=hotspot Next up. Your code. You produced something that is actually a lot better than your previous releases, regardless of your usage of old JDK versions. Better, but not fantastic or good at all. There are quite a few remarks that I can make to hopefully allow you to improve. First of all, your Main class: Code System.out.println("Enter the credit: ");No exception handling. I can simply enter any NaN value and your application will crash because you're not checking the input. I can completely stop your entire game simply by entering a negative credit to begin with, which is something you'll probably want to restrict. I can also break your application by entering a credit value that is smaller than the cost of 'playing'. You should check for this: Code Machine machine = new Machine(3, 0.5, award1, award2);Code if (getCredit() >= gambPri) {This is also completely redundant, I don't know why you keep doing this in your play method: Code public Fruit[] play() {You do not have to keep setting the 'gamb pri' whatever the hell that even means. Doing it once is more than enough and it serves absolutely no purpose at all to set a value to be equal to itself over and over again when playing. You already set this value in the constructor: Code public Machine(int nBoxes, double price, Award... award) {This method right here returns a value yet you never use this value: Code public double increaseCredit(double increase) {Code public void setAvaiCred(double credit) {In your Award class, your constructor is supposed to add a credit to the total balance of the user if he wins, yet you can easily put negative numbers and null arrays in here since you once again do not check the values of the variables that are passed. This can cause behaviour that you do not want for the purpose of this 'game': Code public Award(Fruit[] combination, int a) {You also have quite a few methods in there that serve absolutely no purpose because they're not used anywhere: Code public double collect() {Right here, you do something that is actually quite funny: Code if (Arrays.equals(fruits, collection[i].getCombStock()) == true){Code if (Arrays.equals(fruits, collection[i].getCombStock())){By the way, you also do not close your Scanner. Surely you must know why I tell you this by now.. So to conclude:
Thank you Nemo, for correcting these flaws (which I'm sure you won't, as usual). ![]() |
|
|
| Possibly Related Threads... | |||
| Thread / Author | Replies | Views | Last Post |
| [Shell] by ɩᴄᴀʀᴜȿ ᴌוᴠᴇѕ™Nov 26, 2018 05:48 AM | 9 | 409 |
Nov 26, 2018 05:48 AM Last Post: pms |
| [.NET] by JesperakselJul 23, 2018 08:08 AM | 2 | 150 |
Jul 23, 2018 08:08 AM Last Post: Jesperaksel |
| [C#] by Real AstraAug 27, 2015 02:48 PM | 2 | 138 |
Aug 27, 2015 02:48 PM Last Post: caesay |