所以这就是我需要做的。我有一个具有特定格式的特定文件:https://pastebin.com/rL3jxZAF。一开始的4是房屋数量。我需要在稍后的作业中阅读此文件,但在此作业中我必须说明它是如何阅读它的。它需要了解房子是出租,出售,出租还是出售。它需要有一个地址(包括街道,号码,邮政编码和城市)。它需要看到销售价格和它有什么样的加热系统。
所以我被困在这里: 当我扫描第一行时,包括房子是出售还是出租等等。我不知道该怎么做,因为它需要是一个布尔值,因为卖的是一个单词,出售是2个单词,所以我不喜欢知道如何向java展示它们之间存在差异。我需要将它作为一个字符串扫描并用它来做一些事情来给构造函数一个布尔值,我不知道如何做到这一点。
第二个问题
显然java无法读取对象,所以我需要说这个对象是一个字符串,而后来需要将它转换为一个对象。这不是什么大问题,但问题是我不知道如何将它们实现到构造函数中。我现在非常紧张,所以如果我的解释没有公正,那么这就是任务。我也不知道如何处理所有人和租房类。我需要做些什么。我完全糊涂了。请帮忙。这是作业:https://imgur.com/a/FwCbz 这是我的代码。就像你可以看到很多东西都在评论中,因为它们不起作用:
public static House read(Scanner sc) throws IOException {
//BufferedReader buffer=new BufferedReader(new InputStreamReader(System.in));
//String statuss =buffer.readLine();
Scanner ss = new Scanner(System.in).useDelimiter("\\s");
//String statuss = sc.next();
// boolean status = statuss.equals("FOR RENT") | statuss.equals("FOR SALE");
Address address = Address.read(sc);
int nRooms = sc.nextInt();
sc.next();
sc.next();
int salePrice = sc.nextInt();
String heatingsystemstring = sc.next();
if (heatingsystemstring.equals("boiler")) {
HeatingSystem heatingsystem = new Boiler();
}
if (heatingsystemstring.equals("Centralheating")) {
HeatingSystem heatingsystem = new CentralHeating();
}
if (statuss.equals("FOR RENT") | statuss.equals("RENTED")) {
if ()
RentalHouse house = new RentalHouse(statuss, address, nRooms, salePrice, HeatingSystem);
}
if (statuss.equals("FOR SALE") | statuss.equals("SOLD")) {
OwnerOccupiedHouse house = new OwnerOccupiedHouse(statuss, address, nRooms, salePrice, heatingsystem);
}
}