无法获得返回新聊天以检索值

时间:2015-11-15 21:19:40

标签: java chat

嗨,所以我有一个大学项目,我需要在java中建立一个聊天,只在你执行代码的计算机上工作,你给出两个用户的名字和翻译价值,但我有一个因为我不能使用超级,数组,扩展或内在的问题他们希望我这样做的问题我遇到了一个问题,我现在的问题是我的主要是这样的

import java.util.Scanner;
public class Main {



public static void main(String[] args) {

    Scanner in = new Scanner(System.in);
    Chat ch = null;


    boot(in, ch);
    menu(in, ch);
}

public static Chat boot (Scanner in, Chat ch){


    String name1;
    String name2;
    int transvalue = 0;

    System.out.print("Username 1:");
    name1=in.nextLine();

    do{
    System.out.print("Username 2:");    
    name2=in.nextLine();

    if (name1.equals(name2)){
        System.out.println("Names can't be equal");
        }

    }while(name1.equals(name2));

    do{ 

    System.out.print("Translation Value:");
    transvalue=in.nextInt();
    in.nextLine();
    if (transvalue<1 || transvalue>26){
        System.out.println("Value Can only be between 0 and 26");
    }

    }while(transvalue<1 || transvalue>26);

    return new Chat(name1,name2,transvalue);

    }

所以这个节目将我输入的信息添加到我的课堂聊天

public class Chat {

private static final int id1 = 1;
private static final int id2 = 2;

private Users u1;
private Users u2;
private Conversation conv;

public Chat(String name1, String name2, int transvalue){
    u1 = new Users(id1,name1);
    u2 = new Users(id2,name2);
    conv = new Conversation(transvalue);

}

public static int getId1() {
    return id1;
}

public static int getId2() {
    return id2;
}

public Users getU1() {
    return u1;
}

public void setU1(Users u1) {
    this.u1 = u1;
}

public Users getU2() {
    return u2;
}

public void setU2(Users u2) {
    this.u2 = u2;
}

public Conversation getConv() {
    return conv;
}

public void setConv(Conversation conv) {
    this.conv = conv;
}

}

但是当我添加信息并尝试返回时,例如:

System.out.print(ch.getU1());

或     是System.out.print(ch.getU1()的getName());

我做错了,我做错了吗?

public class Users {

private int id ;
private String name;
private String mess;



public Users(int id,String name){
    this.id=id;
    this.name=name;

}

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}


public String getName() {
    return name;
}

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

任何人都可以找到或指出我做错了什么 感谢所有花时间去帮助的人

0 个答案:

没有答案