BlackHatPlus.com

A forum about BlackHat and Beyond

Please Help Me with Java Program

by Brandon » 2016-02-16 10:17

Hi guys, I got this homework due, and I'm not even sure where to start with this. Ive been fighting for several hours now, and I ended up just deleting all of my programs, and had to start from scratch. Can anyone help me with this task?

Task:

Write a Java application console to play the game rock-paper-scissors. Each user of two types either "P", "R" or "S" (without the quotes). Your code will then announce the winner, as well as the basis for determining the winner: paper covers rock, rock smashed scissors, scissors cut paper, or it is a draw. Your program should allow the user to use lowercase and uppercase letters.

The following are examples of transactions:

Player 1 (insert R for rock, P to the paper, S for scissors): R
Player 2 (enter R to rock, to a paper P, S for scissors): S

Player 1 wins! Crushed stone scissors.

Player 1 (insert R for rock, P to the paper, S for scissors): P
Player 2 (enter R to rock, to a paper P, S for scissors): P

It's a draw!

Player 1 (insert R for rock, P to the paper, S for scissors): P
Player 2 (enter R to rock, to a paper P, S for scissors): S

Player 2 wins! Scissors cut paper.
Brandon
 
Posts: 58
Joined: 2012-12-07 9:42

by Robert » 2016-02-16 22:08

If you need help, you will show some effort. Show us what you have done, or at least talk through your ideas about how you can approach this.

If you do not show effort, unfortunately, your thread will be closed as the violation of the rules.
Robert
 
Posts: 69
Joined: 2012-04-02 9:05

by Herman » 2016-02-17 16:53

As i said i deleted my program for a new start because I ended only in an endless pit of garbage lol. I am trying to write a program using a switch statement, because I know that use (if / else if / else) statement is best saved for comparison of the two objects. So, I could start by asking is that thinking is not correct? should i have to use if / else? whether it makes sense to use a switch statement? what is more efficient? What has a higher quality in terms of neatness?
Herman
 
Posts: 65
Joined: 2012-06-04 9:06

by Garry » 2016-02-18 2:04

I would personally go with a switch statement to this one. There are too many requirements that must be mentioned that it will not be easy on the eyes if carried through if / else-if / else statements. You can create one case per option (rock, paper or scissors) based on the input player1, then check this player2 input within a block of the case and at the same time see if player1 wins or loses.

However, if you are still having trouble with a switch statement, I suggest you do it through if / else-if statements / else first. Once you get to analyze it, try changing the report to switch colleagues for learning purposes.
Garry
 
Posts: 77
Joined: 2011-08-05 9:06

by Craig » 2016-02-18 19:03

Consider using a title that is more useful in the future. Surely something more specific than "Need help with a java program pleaseeeee." Also worth mentioning the extra "e" s in pleaseeee may not do anything to encourage support.
Craig
 
Posts: 85
Joined: 2011-02-07 14:07


Return to Programming Tutorials

cron

Who is online

Users browsing this forum: No registered users and 1 guest
SpinnerChief - WhiteHatBox