我应该为这个项目做什么? [英] What am I supposed to do for this project?

查看:78
本文介绍了我应该为这个项目做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该项目中各类之间的RelationSpaceShips如下:
(1)SpacePort有许多SpaceShip
(2)太空船有一名机长
(3)太空船有引擎
(4)SpaceShip具有一个RegistrationDate
(5)脉冲is-a引擎
(6)扭曲是引擎

(7)太空船有很多船员
(6)人有一个pid(int)
(9)人有-出生日期
(10)上尉是军官
(11)官员是一个人

(12)DateOfBirth是-StarDate
(13)RegistrationDate是-StarDate
(14)StarDate有一天(int)
(15)StarDate有一个月(int)
(16)StarDate已有一年(int)

(17)Enterprise is-a SpaceShip
(18)WarBird is-a SpaceShip
(19)RedShirt是一名船员
(20)船员是一个人





注意:每个对象都有:
私有字符串objName和
public String getName(){返回objName;}


创建一个测试程序,该程序创建一个SpacePort对象,并提示输入
用户输入数据文件的路径.然后程序从数据中读取数据
SpacePort的文件.
然后,打印:
1.属于SpacePort的所有SpaceShip对象,按getName()和
排序 2.属于SpacePort的所有Person对象,按getName()排序
通过创建数据文件并将其填充来测试您的程序
与回答问题的数据.包括
数据文件和run.bat放在项目文件夹中.




规则:
1.除构造函数外,上述每个类还包括:

公共字符串toString(){
//返回所有类名,名称和toString()的字符串
零件.
}
公共无效readFromFile(){
//从用户读取数据,包括objName
}//readIn

2.每个类的数据成员必须声明为私有",并且您不能创建
一个公共函数,它返回除
之外的任何私有数据对象的值 上面的getName().


3.除MainClass外,所有类都应放在一个包中.您的项目应该有
至少3个程序包.


4.如果您正在阅读"C"类的元素,那么"C"是超类
某些其他类中,那么您必须询问用户哪些子类
他们想要的.

例如,假设我们有以下关系SpaceShips:
经销商有很多车
福特是汽车
本田是一辆汽车

那么Dealer的readFromFile()函数可能如下所示:

代码:

< pre>公共无效readFromFile(FileIO fio)引发异常{
if(fio.hasNextInt()== false){
抛出新的Exception("Dealer.readFromFile:missing ncars");
}
int ncars = fio.getNextInt();
carArray =新车[ncars];
for(int i = 0; i& lt; carArray.length; i ++){
if(fio.getNextLine()== false){
抛出新的Exception("Dealer.readFromFile:missing ncars");
}
字符串cartype = fio.getNextLine();
if(cartype.equals("f")){
carArray [i] =新的Ford();
}其他{
carArray [i] = new Honda();
}
carArray [i] .readFromFile(fio);
}//对于carrArray中的每辆车

}//readFromFile

您可以假定类fileioPkg.FileIO是您的项目的一部分:
软件包fileioPkg;
导入java.util.*;
导入java.io. *;
公共类FileIO {
//该类充当静态的生产者"类,该类在被
后 //以文件名初始化,
私人FileReader freader;
私人扫描仪scan = null;
公共FileIO(){
freader = null;
scan = null;
}//默认const
公共FileIO(String filename)抛出FileNotFoundException {

文件内文件;

FileReader阅读器;
infile =新文件(文件名);

reader =新的FileReader(infile);
scan =新的Scanner(阅读器);
}//(String)构造函数
public boolean hasNextInt()引发异常{
if(scan == null){
引发新的Exception("FileIO.getNextInt:文件未打开");
}其他{
返回scan.hasNextInt();
}
}//hasNextInt
public int getNextInt()引发异常{
if(scan == null){
引发新的Exception("FileIO.getNextInt:文件未打开");
}其他{
int iv = scan.nextInt();
System.out.println("FileIO.getNextInt:" + iv);
返回iv;
}
}//getNextInt

public boolean hasNextLine()引发异常{
if(scan == null){
引发新的Exception("FileIO.getNextInt:文件未打开");
}其他{
返回scan.hasNextLine();
}
}//hasNextLine
公共字符串getNextLine()引发异常{
if(scan == null){
引发新的Exception("FileIO.getNextInt:文件未打开");
}其他{
字符串result = scan.nextLine().trim();
System.out.println("FileIO.getNextLine:" + result);
返回结果;
}
}//getNextLine


public boolean hasNextDouble()引发异常{
if(scan == null){
引发新的Exception("FileIO.getNextInt:文件未打开");
}其他{
返回scan.hasNextDouble();
}
}//hasNextDouble
公共double getNextDouble()引发异常{
if(scan == null){
引发新的Exception("FileIO.getNextInt:文件未打开");
}其他{
double dv = scan.nextDouble();
System.out.println("FileIO.getNextDouble:" + dv);
返回dv;
}
}//getNextDouble
public void close(){
尝试{
freader.close();
} catch(IOException e){
//ignore
}
}//close

}//class FileIO
</pre>

到目前为止,我已经创建了所有类,例如SpacePort,Crewman等.我已经创建了超类,例如SpaceShip扩展了SpacePort.我创建了一个主类,要求用户输入一个txt文件.但是从他的位置开始,我就被困在要做的事情上.我不知道txt文件应该是什么样子以及程序要做什么.有人可以用白痴证明的方式向我道歉吗?抱歉,我还是java的新手.♠♠

The relationSpaceShips between the classes in this project is as follows:
(1) SpacePort has-many SpaceShip
(2) SpaceShip has-a Captain
(3) SpaceShip has-a Engine
(4) SpaceShip has-a RegistrationDate
(5) Impulse is-a Engine
(6) Warp is-a Engine

(7) SpaceShip has-many Crewman
(6) Person has-a pid (int)
(9) Person has-a DateOfBirth
(10) Captain is-a Officer
(11) Officer is-a Person

(12) DateOfBirth is-a StarDate
(13) RegistrationDate is-a StarDate
(14) StarDate has-a day (int)
(15) StarDate has-a month (int)
(16) StarDate has-a year (int)

(17) Enterprise is-a SpaceShip
(18) WarBird is-a SpaceShip
(19) RedShirt is-a Crewman
(20) Crewman is-a Person





NOTE:every object has:
private String objName, and
public String getName() {return objName;}


Create a test program that creates an SpacePort object, and prompts for
the user to enter the path of a data file. The program then reads the data from the data
file for the SpacePort.
Then, print:
1. all SpaceShip objects belonging to the SpacePort, sorted by getName(), and
2. all Person objects belonging to the SpacePort, sorted by getName()

Test your program by creating a data file and filling it in
with the data that answers the questions. Include the
data file and run.bat in the project folder.




Rules:
1. Each class above includes, in addition to the constructors:

public String toString(){
//return a string of the classname, the name, and toString() of all
parts.
}
public void readFromFile(){
//read the data from the user, including objName
}//readIn

2. The data members of each class MUST be declared "private" and you may not create
a public function that returns the value of any private data object, other than
getName() above.


3. All classes, except MainClass, should be in a package. Your project should have
at least 3 packages.


4. if you are reading in an element of class "C", where "C" is a superclass
of some other classes, then you must ask the user which of the subclasses
they want.

For example, suppose we have these relationSpaceShips:
Dealer has-many Car
Ford is-a Car
Honda is-a Car

then the readFromFile() function for Dealer might look like this:

Code:

<pre> public void readFromFile(FileIO fio) thows Exception{
if(fio.hasNextInt()==false){
throw new Exception("Dealer.readFromFile:missing ncars");
}
int ncars = fio.getNextInt();
carArray = new Car[ncars];
for(int i=0;i&lt;carArray.length;i++){
if(fio.getNextLine()==false){
throw new Exception("Dealer.readFromFile:missing ncars");
}
String cartype=fio.getNextLine();
if(cartype.equals("f")){
carArray[i]= new Ford();
}else{
carArray[i]= new Honda();
}
carArray[i].readFromFile(fio);
}//for each car in carrArray

}//readFromFile

You may assume that class fileioPkg.FileIO is part of your project:
package fileioPkg;
import java.util.*;
import java.io.*;
public class FileIO {
//this class acts as a static "producer" class that,after being
//initialized with a filename,
private FileReader freader;
private Scanner scan=null;
public FileIO(){
freader=null;
scan=null;
}//default const
public FileIO(String filename) throws FileNotFoundException{

File infile;

FileReader reader;
infile = new File(filename);

reader = new FileReader(infile);
scan = new Scanner(reader);
}//(String) constructor
public boolean hasNextInt() throws Exception{
if(scan==null){
throw new Exception("FileIO.getNextInt:file not opened");
}else{
return scan.hasNextInt();
}
}//hasNextInt
public int getNextInt() throws Exception{
if(scan==null){
throw new Exception("FileIO.getNextInt:file not opened");
}else{
int iv=scan.nextInt();
System.out.println("FileIO.getNextInt:"+iv);
return iv;
}
}//getNextInt

public boolean hasNextLine() throws Exception{
if(scan==null){
throw new Exception("FileIO.getNextInt:file not opened");
}else{
return scan.hasNextLine();
}
}//hasNextLine
public String getNextLine() throws Exception{
if(scan==null){
throw new Exception("FileIO.getNextInt:file not opened");
}else{
String result=scan.nextLine().trim();
System.out.println("FileIO.getNextLine:"+result);
return result;
}
}//getNextLine


public boolean hasNextDouble() throws Exception{
if(scan==null){
throw new Exception("FileIO.getNextInt:file not opened");
}else{
return scan.hasNextDouble();
}
}//hasNextDouble
public double getNextDouble() throws Exception{
if(scan==null){
throw new Exception("FileIO.getNextInt:file not opened");
}else{
double dv=scan.nextDouble();
System.out.println("FileIO.getNextDouble:"+dv);
return dv;
}
}//getNextDouble
public void close(){
try {
freader.close();
} catch (IOException e) {
//ignore
}
}//close

}//class FileIO
</pre>

So far I created all the classes such as SpacePort, Crewman etc. I created the super classes for example SpaceShip extends SpacePort. I created a mainclass which asks the user to enter a txt file. But fromt his spot I am stuck on what I am so post to do. I have no idea how the txt file is supposed to look like and what the program is to do. Can someone please exaplin this to me in idiot proof terms. Sorry I am still new to java.♠♠

推荐答案

该文本文件应该看起来像您想要的样子.您的老师没有为其指定结构,因此您可以创建它.

您可能会花哨的并将其创建为XML文件,也可以仅创建一个简单的逗号分隔文件.行中的第一项可以说出它是什么类型的对象,例如SpacePort,然后可以跟随数据.

如果您还有其他问题,您确实应该向老师的助手或老师本人询问...或找一位好老师.
The text file is supposed to look like what you want it to look like. Your teacher didn''t specify a structure for it, so you get to create it.

You could get fancy and create it as an XML file, or you could just create a simple comma-delimited file. The first item in a line can say what type of object it is, like SpacePort and then the data can follow.

If you have more questions, you really should ask a teacher''s assistant or the teacher themselves...or find a good tutor.


我在Java论坛中回答了这个问题.请不要张贴在一个以上的地方. :mad:
I answered this in the Java forum. Please do not post in more than one place. :mad:


这篇关于我应该为这个项目做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆