• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Array solution for Tennis Game

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I get it. The story of the winner() method tells if the player wins or not. One responsibility

I will find myself in a not later on when doing the Add in Add on, because of my conditions, will I?

is this what you meant by the code:


 
Sheriff
Posts: 14990
250
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Lg Long wrote:The story of the winner() method tells if the player wins or not. One responsibility


Yes on one responsibility. Not quite the story as you describe it though. I'm thinking more along the line of the winner() method saying who the winner is, not if the player wins or not. It may seem trivial but it's still a significant distinction, same as the difference between "Who won the lottery?" and "Did I win the lottery?"

Again, consider that a winner can be determined immediately when they win the game point. You have two methods that can award a point to a player. That's where I would put the logic to determine if there was a winner. Depending on who won the point, that's who I would put down as the winner. Until someone actually wins the game point, however, the winner is "nobody". So, another design decision you have to make is "How do I represent the state of there being no winner yet?" (Hint: null vs. not null)
 
Lg Long
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
   Work aside and type for a joke: I eat allot. My friend is asking how can I do that and remain supple. I said "the brain consumes a lot of energy. The dumbest the more. Stay dumb. Stay skinny "

       I was about to write the whole 'if it works let me be for now'. But I run the test and I get null, lol.

       ok, this is my code so far. It is screwed. As soon as I try to pass:



failing:
it_gives_receiver_score_second()
Expected :15 - Love
Actual   :Ad out

it_gives_receiver_score_second()
Expected :15 - Love
Actual   :Ad out

it is Ad in when deuce and server wins point()
java.lang.ArrayIndexOutOfBoundsException: 4


Please no more riddles, I can't focus anymore and I need to finish. Could use some straight forwards examples, from which to pick answers. I can barely read your explanations. By the time I finish I am more confused then when i started
 
Lg Long
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
posted 2 times as the platform was loading and I submitted the same post.
please delete.
Content minimized. Click to view
 
Lg Long
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my atAdvantagePoint



I don't know how to write the isServerUp() -> can I get some help?




also I need to take one instance of server and receiver out, else I get the java.lang.ArrayIndexOutOfBoundsException: 4

 
Junilu Lacar
Sheriff
Posts: 14990
250
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The idea behind isServerUp() was that the server has more points than the receiver.
 
Junilu Lacar
Sheriff
Posts: 14990
250
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Lg Long wrote:also I need to take one instance of server and receiver out, else I get the java.lang.ArrayIndexOutOfBoundsException: 4


If you're going to use the tests I wrote to drive your implementation, you have to understand some of the underlying decisions I used to get things to work. You're getting an index out of bounds error because you're not treating a point value of 4 as a special case. The SCORE array only has 4 values in it for the "normal" scoring cases. Once the point value goes to 4, then you shouldn't be accessing the SCORE array.

The scheme is Deuce is always 3-3. Ad-in (server has advantage) is always 4-3. Ad-out (receiver has advantage) is always 3-4. The logic flow has to adhere to this scheme. If not, that's when you get the index out of bounds exception.
 
Lg Long
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

you're not treating a point value of 4 as a special case.



how can I do that?
can I please get some coding examples?

all I get pesudo explanations and i don't have experience enough to interpret all this

I don't have a direction, example other exercises to tie too. This is really frustrating
 
Junilu Lacar
Sheriff
Posts: 14990
250
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At this point, I have probably given you more code than I actually should have. I'm not sure giving you any more code is the right thing to do. Sorry if you're stuck but you're going to have to get unstuck yourself here if you really want to learn.
 
Lg Long
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok. as I said before, I am pressured by time and as much as i want to learn I need to sort this out so I can pass my assessment.
sometimes you need to lose a battle to win the war, and this is a battle that I can lose to gain more time to learn. If I fail, it won't matter that I did this by myself or not.

It's fine. I'll find another way. Thank you for the help
 
Lg Long
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, i have my model solved. Can I get some help with the controller, please?
I don't have a picture of what should look like in this example.
I could use some code for starters. Maybe empty methods?

I'll try one more time to help you organise your thoughts. You need to implement MVC and you've actually started down a good path with that. You already have code for a Controller, that's the game loop that you kind of patterned after an example I gave. Here's a breakdown of responsibilities of different classes that would make up MVC:

View (GameView class)
1. Displays menu
2. Gets input from user
3. Displays status of the game (as provided by the model, through the controller)

Controller (GameController class)
1. Tells the View to display menu
2. Tells the View to get user input (the action)
3. Dispatches user input to appropriate actions
4. Calls appropriate methods in the model to carry out actions requested
5. Passes results of the action performed back to the view for display, if any.

Model (Game class)
1. Keep track of the state of the game - keeps score and determines if game is over
2. Provide methods to change the state of the game - serverWinsPoint(), receiverWinsPoint()
3. Provide method to report the state of the game (getScore(), hasWinner())

That's it! With the four menu options you're supposed to provide to the user (1-Award server a point, 2-Award receiver a point, 3-Show score, 4-Exit) you have everything in the above description to implement a program that does all that.

 
Junilu Lacar
Sheriff
Posts: 14990
250
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Lg Long wrote:So, i have my model solved. Can I get some help with the controller, please?
I don't have a picture of what should look like in this example.
I could use some code for starters. Maybe empty methods?



I already posted most of the code that would go in the game loop. Just go back over the thread again.
 
Lg Long
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thank you for your help.

I was thinking of something else, that is why I became confused. All I had to do in my Controller model, was to print the get score in case 1 and 2.

The structure for TennisGame project: TennisGame(model); TennisMenu(controller); Main(view)

I can't stop thinking of the model I did for the Natural Reserve project, where I learned how to use build a model - Pojo, controller, I had a Factory for the name of the bird to be what I wanted to be called, the Controller was the NaturalReserver class, having methods such as add, retrieve, count etc in it; the View was the menu& Scanner and Main was just an entry point.

Ex: Player(model), TennisGame(controller), TennisMenu(view), Main(program entry point)


Any suggestions on ho to refractor this project to the same structure as above. O why not do it?
 
What do you have in that there bucket? It wouldn't be a tiny ad by any chance ...
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!