日期:2014-05-20  浏览次数:20769 次

类问题
这个题的题目是:
设计一个类,分别设计3个method,第一个可以输入自己的名字和性别,第二个可以输入   自己的生日的电话,最后可以将所有的数据输出出来


下面是我自己编的,由于初学,所以还是个菜鸟,编译了一下,存在很多错误,请大家给指正一下,应该怎么编啊


class   CPerson
{
    private   String   name;
    private   String   sex;
    private   String   bithnum;
    public   void   input()   throws   IOException
      {
          String   na,se;
          BufferedReader   buf;
          buf=new   BufferedReader(new   InputStreamReader(System.in));
          System.out.print( "input   the   name: ");
          na=buf.readLine();
          name=na;
          System.out.print( "input   the   sex: ");
          se=buf.readLine();
          sex=se;
      }
    public   void   inputbn()   throws   IOException
      {
          String   bn;
          BufferedReader   buf;
          buf=new   BufferedReader(new   InputStreamReader(System.in));
          System.out.print( "input   the   number: ");
          bn=buf.readLine();
          bithnum=bn;
      }
    public   void   output()
    {
      System.out.println( "name= "+name+ ",sex= "+sex+ ",bithnum= "+bithnum);
    }
}

public   class     app8_5
{
    public   static   void   main(String   args[])   throws   IOException
    {
        CPreson   per=new   CPerson();
        per.input();
        per.inputbn();
        per.output();
    }
}

------解决方案--------------------
import java.io.*;


class CPerson
{
private String name;
private String sex;
private String bithnum;
public void input() throws IOException
{
String na,se;
BufferedReader buf;
buf=new BufferedReader(new InputStreamReader(System.in));
System.out.print( "input the name: ");
na=buf.readLine();
name=na;
System.out.print( "input the sex: ");
se=buf.readLine();
sex=se;
}
public void inputbn() throws IOException
{
String bn;
BufferedReader buf;
buf=new BufferedReader(new InputStreamReader(System.in));
System.out.print( "input the number: ");
bn=buf.readLine();
bithnum=bn;
}
public void output()
{
System.out.println( "name= "+name+ ",sex= "+sex+ ",bithnum= "+bithnum);
}


public static void main(String args[]) throws IOException
{
CPerson per=new CPerson();
per.input();
per.inputbn();
per.output();
}
}
------解决方案--------------------