• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Bank Class for a street craps game

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Given the following information:

The Bank class represents the Bank in a Craps game. The Bank takes the players bets. The Bank is a data class. The only information we need to manage (the field or class variable) is how much money we need to payout to the winner. If the winner bets $10, then the bank matches that for $20. The winner gets the $20.

  • total payout (Double)


  • Methods are needed to manage this data.

  • placeBet - takes a double as an input parameter. If the input value is not negative, then the value is multiplied by 2, added to the payout value, and true is returned. otherwise, false is returned
  • payout - returns the value of the payout and sets the payout to zero.
  • getTotal - return the value of the payout


  • So my question is, how would I go about creating this class given that information? I have already attempted it, but I feel like I am not even close to the goal I am being asked for, if the code even works.
     
    lowercase baba
    Posts: 13089
    67
    Chrome Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    What have you tried?  

    FWIW...i think these directions aren't terribly clear. But post what you've got, and we'll help you whip it into shape.
     
    Mike Corona
    Ranch Hand
    Posts: 71
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
     
    Sheriff
    Posts: 17644
    300
    Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    You code looks like it should work.  A couple of very minor nitpicks but otherwise, the formatting is good, the names you chose are decent enough. Is there anything in particular that is troubling you about your code?
     
    Mike Corona
    Ranch Hand
    Posts: 71
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    This will also be integrated together with a Die class and DicePlayer class to create the actual craps game later on, but for now I don't understand this portion. I can post those up if needed btw. Also, thank you very much for your help
     
    Junilu Lacar
    Sheriff
    Posts: 17644
    300
    Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    ...and Welcome to the Ranch!
     
    Mike Corona
    Ranch Hand
    Posts: 71
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Junilu Lacar wrote:You code looks like it should work.  A couple of very minor nitpicks but otherwise, the formatting is good, the names you chose are decent enough. Is there anything in particular that is troubling you about your code?


    Well, I don't think the payOut method is correct, but I also do not have the testing code being used to compile it either.
     
    Mike Corona
    Ranch Hand
    Posts: 71
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Junilu Lacar wrote:...and Welcome to the Ranch!


    Thank you! Seems more pleasant than stack overflow so far. They chewed me apart for not asking a question to their standards.
     
    Junilu Lacar
    Sheriff
    Posts: 17644
    300
    Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Mike Corona wrote:Well, I don't think the payOut method is correct, but I also do not have the testing code being used to compile it either.


    What do you think is wrong with it? I don't see anything that jumps out at me as wrong. In fact, it looks correct to me, per the requirements you gave. Maybe I'm missing something. Of course, you can write your own unit test, too.
     
    Ranch Hand
    Posts: 146
    4
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Also posted at: https://www.java-forums.org/new-java/96927-bank-class-street-craps-game.html
     
    Marshal
    Posts: 79179
    377
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Welcome again
    Norman is right; you shoul‍ld always inform people on both websites if you post something twice.

    I never like assignments where the teacher provides lots of details. What is more, I would have preferred you to be able to pick your own datatype for the bet. If the instructions say double, you are stuck with doubles, though looking here in the Java™ Tutorials tells you that doubles are not suitable for money. If you look here, you find there is a class specially designed for money.
     
    Campbell Ritchie
    Marshal
    Posts: 79179
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    By the way: why do you think the method to pay the bet is incorrect? I agree with Junilu that your method looks correct. It is a bit awkward to read, maybe, but I think correct. You haven't been taught how to throw exceptions yet, have you? I would prefer to throw an exception for a non‑positive argument, rather than having the positive field.
     
    Mike Corona
    Ranch Hand
    Posts: 71
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Campbell Ritchie wrote:By the way: why do you think the method to pay the bet is incorrect? I agree with Junilu that your method looks correct. It is a bit awkward to read, maybe, but I think correct. You haven't been taught how to throw exceptions yet, have you? I would prefer to throw an exception for a non‑positive argument, rather than having the positive field.



    Sorry about that, I did not know I should inform both websites I have posted this topic twice, but I know for future reference. I have not been taught to throw exceptions yet unfortunately, but I guarantee my teacher is using them in the tester. Also, I am stuck to doubles because my teacher has made it a rule in the instructions. I just keep thinking it is wrong somewhere because he created a tester for his grading terms, but I have no access to it. He uses zybooks so there is a bit of a block. Honestly, I don't think I would understand his tester either way considering he would be using things he has not taught us as of yet.
     
    Mike Corona
    Ranch Hand
    Posts: 71
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Mike Corona wrote:

    Campbell Ritchie wrote:By the way: why do you think the method to pay the bet is incorrect? I agree with Junilu that your method looks correct. It is a bit awkward to read, maybe, but I think correct. You haven't been taught how to throw exceptions yet, have you? I would prefer to throw an exception for a non‑positive argument, rather than having the positive field.



    Sorry about that, I did not know I should inform both websites I have posted this topic twice, but I know for future reference. I have not been taught to throw exceptions yet unfortunately, but I guarantee my teacher is using them in the tester. Also, I am stuck to doubles because my teacher has made it a rule in the instructions. I just keep thinking it is wrong somewhere because he created a tester for his grading terms, but I have no access to it. He uses zybooks so there is a bit of a block. Honestly, I don't think I would understand his tester either way considering he would be using things he has not taught us as of yet.



    I also meant to mention the reasoning why I think it is wrong. Everytime I enter the code into zybooks, it tells me I am wrong and provides no feedback as to where I am wrong. I have tried changing code numerous times to fix it, but have not succeeded.
     
    Junilu Lacar
    Sheriff
    Posts: 17644
    300
    Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    You might want to check the exact spelling of the method names in the instructions.  If the instructions said the method should be named "payout" and your code has "payOut" then your teacher's tester will not find the method it's looking for.  Remember, Java is case-sensitive.
     
    Mike Corona
    Ranch Hand
    Posts: 71
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Junilu Lacar wrote:You might want to check the exact spelling of the method names in the instructions.  If the instructions said the method should be named "payout" and your code has "payOut" then your teacher's tester will not find the method it's looking for.  Remember, Java is case-sensitive.


    I noticed cows are like check marks on stack overflow. How do I give you one because you just solved the issue. Incredible, yet such a simple mistake. The code was correct besides that one thing. Thank you so much!
     
    Junilu Lacar
    Sheriff
    Posts: 17644
    300
    Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    No problem. Today's the first day of Lent, so I'm actually fasting. No need for cows for another 40 days.
     
    Campbell Ritchie
    Marshal
    Posts: 79179
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Junilu Lacar wrote:. . .  If the instructions said the method should be named "payout" and your code has "payOut" . . .

    Another reason for not overspecifying assignments. You are not programming, but working to satisfy a machine. And is it spelt payout or pay out in normal English? If the name of a method shou‍ld be an instruction, then it is two words and you shou‍ld capitalise the second wor‍d when you join two words like that. But you have to do what the machine wants to get the marks.

    Cows are better than tick marks: you can click the (=+1) button for a tick. A cow is like giving ten ticks simultaneously. Granting cows is restricted, however; only certain people can give them. Apology accepted about the cross‑post
     
    Rancher
    Posts: 4801
    50
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    As I said over on the other forum, if the machine needs a specific spelling (and they usually do) then the exercise should provide the skeleton to fill in.
     
    Where does a nanny get ground to air missles? Protect this tiny ad:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic