佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 863|回复: 2

JAVA Programming问题..

[复制链接]
发表于 13-11-2006 10:18 PM | 显示全部楼层 |阅读模式
请问我错了什么?可以帮我改吗?我老师说我做错了...答案在下面.谢谢~
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( );
        }
}
回复

使用道具 举报


ADVERTISEMENT

发表于 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 的.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 25-8-2025 10:52 AM , Processed in 0.121860 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表