I get the error: Static Error: This class does not have a static void main method accepting String[]. The console also tells me that it runs Guest. However, I start my code with Hotel with the main, so I do not understand why it start with Guest. I used for some classes a constructor. To my knowledge I do not need to have a constructor for every class.
This is my code:
import java.util.*;
class Guest {
String name;
static Scanner sc = new Scanner(System.in);
Guest() {
name = "NN";
}
void setName() {
//static Scanner sc = new Scanner(System.in);
name = sc.next();
}
void printName() {
System.out.println(name);
}
}
class Room {
Guest guest;
int number;
// Room() {
// number = 1;
//}
void newGuest() {
guest = new Guest();
}
void nameGuest() {
guest.setName();
}
void printRoom() {
System.out.println(number);
guest.printName();
}
}
class Hotel {
Room[] rooms;
Hotel(int b){
rooms = new Room[b];
}
void printRooms() {
for(int i=0; i<rooms.length; i++) {
rooms[i].printRoom();
System.out.println();
}
}
public static void main(String[] args) {
new Hotel(4).demo();
}
void demo() {
for(int i=0; i<rooms.length; i++) {
rooms[i].newGuest();
rooms[i].nameGuest();
}
printRooms();
}
}