高分求救 java问题

来源:百度知道 编辑:UC知道 时间:2024/05/11 19:54:34
请问 java中 如何调用带参数的方法 (在同一个类中)
import java.util.*;
public class game {
Scanner input=new Scanner(System.in);
public void person(){

String name;
String computer="曹操";
System.out.println("请选择玩家姓名");
System.out.println("1.张飞 2.关羽");
int num=input.nextInt();
switch(num){
case 1:
name="张飞";
break;
case 2:
name="关羽";
break;
}
}
public void startgame(){

System.out.println("请出拳 1.剪刀 2.石头 3.布");
int num1=input.nextInt();
switch(num1){
case 1:
System.out.println("你出的是 剪刀");
break;
case 2:
System.out.println("你出的是 石头");
break;
case 3:
System.out.println("你出的是 布");
break;
}
int num2=(int)(Math.random()*10%3+1);//电脑出拳
if(num2==1){
System.out.println("电脑

类名的首字母大写,这是一个良好习惯.
public class start {
public static void main(String[] args) {
game text=new game();
text.person();
text.startgame();
text.pan(num1,num2); //num1和num2并没在定义过
text.showgame(count, com, people, name, computer);
//count,com.people.name.computer都没有定义过.
}

text.pan(num1,num2);

//num1和num2 在哪里定义的?

text.showgame(count, com, people, name, computer);

//count,com.people.name.computer的定义lz能不能补充一下?.

text.pan(num1,num2);
text.showgame(count, com, people, name, computer);
我想请问一下楼主,你这两个函数里的参数是从哪来的?在main函数里都没有定义,没有初始化,那么它怎么能以实参的身份传给形参呢?
你能写出这么个程序,相信你是一时昏了头啊,呵呵

text.pan(num1,num2);
text.showgame(count, com, people, name, computer);
兄弟你这是调用另外一个类中的参数啊,能不出错吗?另外一个类中的参数要用get方法得到,或者设置为静态属性,或者通过返回值来获取