So this is what I need to do. I have a specific file with a specific format to it: https://pastebin.com/rL3jxZAF. The 4 at the beginning is the number of houses. I need to read this file in a later assignment, but in this assignment I have to say how it needs to read it. It needs to read whether the house is for rent, for sale, rented or sold. It needs to have an address(which consists of a street, number, zipcode and city). It needs to see the sale price and what kind of heating system it has.
So I am stuck here: When I scan the first line including if the house is sold or rented etc. I don't know how to do this, because it needs to be a boolean and because sold is one word and for sale is 2 words, so I don't know how to show java that there is a difference between them. I need to scan it as a string and do somethings with it to give the constructor a boolean and I don't know how to do this all.
Second problem
Obviously java can't read objects, so I need to say that this object is a string and than later need to convert it to an object. This is not a big deal but the problem is that I don't know how to implement them into the constructor. I am very stressed right now, so if my explanations didn't do any justice, here is the assignment. I also don't know what do with the owneroccupied and rentalhouse class. What do I need to do in them. I am totally confused. Please help. Here is the assignment: https://i.stack.imgur.com/7IPlL.jpg And here is the code I have. Like you can see many things are in comments because they don't work:
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);
}
}