当前位置: 代码迷 >> J2SE >> 功课不知道哪不对,运行不出
  详细解决方案

功课不知道哪不对,运行不出

热度:65   发布时间:2016-04-23 20:00:52.0
作业不知道哪不对,运行不出
System.out.println("用户名:"per[i].getName()+"口令:"per[i].getPassword()+
"总个数:"+count)
 ;,说解析类型不对

 per. prit() ;也不行  应该怎么修改呢?


/*设计一个表示用户的User类,类中的变量有用户名、口令和记录用户个数的变量
(静态的)定义类的3个构造方法(没有参数、有一个参数给用户赋值、有两个参数
给用户名和口令赋值)、获取和设置口令的方法、返回字符串表示的类信息的方法
(包括用户名、口令)。编写应用程序测试Use类*/

class User{
private String  name ;
private String password ;
private static int count=0 ;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getCount() {
return count;
}
public User(){
count++ ;

}
public User(String name){  //统计产生对象
this.setName(name);
count++ ;
}
public User(String name,String password){
this.setName(name) ;
this.setPassword(password) ;
count++ ;
}

public void prit(){
for(int i=0;i<count;i++){
System.out.println("用户名:"per[i].getName()+"口令:"per[i].getPassword()+
"总个数:"+count) ;
}
}
}  ;
public class Demo01{
public static void main(String args[]){
User per[]=new User[3];
per[0]=new User("A","123acd");
per[1]=new User("B","123acd") ;
per[2]=new User("C","123acd") ;
               per. prit() ;

}
} ;


------解决思路----------------------
貌似输出字符串少两个加号。。
------解决思路----------------------
per的类型是User型的数组。针对该数组的函数prit是没有定义的。

package com.yuyu.a;

class User {
private String name;
private String password;
private static int count = 0;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public int getCount() {
return count;
}

public User() {
count++;

}

public User(String name) { // 统计产生对象
this.setName(name);
count++;
}

public User(String name, String password) {
this.setName(name);
this.setPassword(password);
count++;
}

public void prit() {
System.out.println("用户名:" + this.getName() + "口令:" + this.getPassword());
}

public static void main(String args[]) {
User per[] = new User[3];
per[0] = new User("A", "123acd");
per[1] = new User("B", "123acd");
per[2] = new User("C", "123acd");

for (int i = 0; i < per.length; i++) {
per[i].prit();
}
}
};
------解决思路----------------------
per是数组对象,print方法是定义在per数组的元素user中的
  相关解决方案