Background: Beginner in programming, very new to this whole "Java" thing.
I love the help, but I do not want a direct answer, more like a point in the right direction, or any which way where I can learn instead of blindly copy/paste. Instead of "heres the right code" more of "hears how you can get the right code" Thank you :)
Ok so my question is, what is wrong with the prompt ad the IF/THEN statement. When I run it with the prompt, it says cannot find symbol - method prompt(java.lang.String) Without the prompt, when I run it, after I input my choice, whether right or wrong, it always returns "Sorry, that is'nt a choice. Choose rock, paper or scissors!" even if it is right!
If you need any more info on my problem, let me know :) Anyway here is the class:
//Player class
import java.util.Scanner;
import java.lang.String;
public class Player
{
private String name;
private String choice;
public Player(String nm)
{
name = nm;
}
public Player(String nm, String ch)
{
name = nm;
choice = ch;
}
public void setName( String nm)
{
name = nm;
}
public void setChoice( String ch )
{
}
public String getChoice()
{
Scanner scan = new Scanner (System.in);
System.out.println("Choose rock, paper or scissors:");
String player = scan.next(); player.toLowerCase();
if ((player != ("rock"))
|| (player != ("paper"))
|| (player != ("scissors")))
{
System.out.println("Sorry, that is'nt a choice. Choose rock, paper or scissors!");
player = prompt("Choose rock, paper or scissors:");
}
else
{
System.out.println("Good choice!");
}
System.out.println("You chose " + player);
return "";
}
public String getName()
{
Scanner scan = new Scanner (System.in);
System.out.println("Whats your name?");
String name = scan.next();
return "";
}
public String toString()
{
return "";
}
}
And the runner:
public class PlayerRunner
{
public static void main(String[] args)
{
Player s = new Player("Michael Jackson", "rock");
System.out.println(s.getChoice());
System.out.println(s.getName());
//outs rock
//call the getName() method
System.out.println(s); //outs Michael Jackson rock
//set the choice to paper
System.out.println(s); //outs Michael Jackson paper
//instantiate a new Player named jb named Jim Bob that chose scissors
//print out Jim Bob
}
}
The goal of this portion was titled to: "Use the Player.java file to create the player. Complete the Player constructors, set methods, get methods, and the toString. Use PlayerRunner.java to test your Player class."
Let me know if you see that I did anything else wrong :) Again I'm a beginner, but I'm here to learn, not just paste the right answer and move on. Thank you!!
Aucun commentaire:
Enregistrer un commentaire