首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

类有关问题

2012-01-23 
类问题这个题的题目是:设计一个类,分别设计3个method,第一个可以输入自己的名字和性别,第二个可以输入自己

类问题
这个题的题目是:
设计一个类,分别设计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();
}
}
------解决方案--------------------


你没有导包 还有就是一个类名写错了

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 class app8_5 {
public static void main(String args[]) throws IOException {
CPerson per = new CPerson();
per.input();
per.inputbn();
per.output();
}
}

热点排行