查看: 865|回复: 2
|
JAVA Programming问题..
[复制链接]
|
|
请问我错了什么?可以帮我改吗?我老师说我做错了...答案在下面.谢谢~
Hobbiton Town is a fictitious town populated by a race called hobbits.
You are to develop a program to allow users t keep track on the hobbits in Hobbits Town.
A HobbitRec contains the below information:
-HobbitID - 10 characters
-Name - 30 characters
-DateOfBirth - date format : dd/mm/yyyy
-Height - float type
-Weight - float type
You program should be able to store up to 100 HobbitRec records in an array called HobbitsArray.
Your program should at least perform the below operations:
-Add new hobbit records in HobbitsArray
-Display all hobbit's records
-Find and display a particular hobbit given the name or HobbitID
Requirement:
Your program should apply the concepts of class, array of objects and constructor.
答案:import java.io.*;
class Hobbit
{
protected String id;
protected String name;
protected String dob;
protected float height;
protected float weight;
protected void get(){
try{
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
System.out.println("Registration Form");
System.out.println("================");
System.out.println("Enter Your HobbitID: ");
id = br.readLine();
System.out.println("Enter Hobbit Name: ");
name = br.readLine();
System.out.println("Enter Date of Birth (DD/MM/YYYY): ");
dob = br.readLine();
System.out.println("Enter Your Height (CM): ");
height = Float.parseFloat(br.readLine());
System.out.println("Enter Your Weight (KG): ");
weight = Float.parseFloat(br.readLine());
} catch (IOException e ) { }
}
protected void show( ) {
System.out.println("");
System.out.println("========================== ");
System.out.println("Profile");
System.out.println("========================== ");
System.out.println("HobbitID:" + id );
System.out.println("Hobbit Name:" + name );
System.out.println("Date of Birth:" + dob );
System.out.println("Height:" + height + " CM" );
System.out.println("Weight:" + weight + " KG" );
}
public static void main(String args[ ] ){
Hobbit cn = new Hobbit( );
cn.get( );
cn.show( );
}
} |
|
|
|
|
|
|
|
发表于 24-11-2006 02:09 AM
|
显示全部楼层
这个看起来是10天前的贴,不知道楼主解决了没有。
我看了的确有点意见,就是,楼主只是apply了concepts of classer而以。
array of objects 和 constructor楼主没做到。。。。。 |
|
|
|
|
|
|
|
发表于 24-11-2006 09:31 AM
|
显示全部楼层
老师说的没错, 你完全做错了, 完全没有 class 和 object array 的概念. 你的 program 只是一个普通的执行软件.
正确的做法应该是, 制作出 hobbit class, 然后用另一个执行的 class 来呼叫 hobbit class, 执行的 class 可以是 DOS 的(就好象你现在所写的), 或 windows 的. |
|
|
|
|
|
|
| |
本周最热论坛帖子
|