NetBeans не разрешит мне запускать мою программу из-за проблемы, связанной с публичным классом HotelManagement и публичным классом Room. Может ли кто-нибудь помочь мне исправить эту проблему, чтобы моя программа работала плавно. БлагодаряСправка по классам, предметам и методам Java
public class HotelManagement {
public static void main(String[] args) {
Room room1 = new Room(3348, 80, "Single Bed");
Room room2 = new Room(3347, 90, "Double Bed");
Room room3 = new Room(3346, 140, "Suite");
room1.Book();
room2.printRoomInfo();
room3.setRate(180);
room1.Release();
room1.printRoomInfo();
room3.printRoomInfo();
}
}
public class Room {
private final int number;
private final String type;
private int rate;
private boolean isBooked;
public Room(int number, int rate, String type) {
this.number = number;
this.type = type;
this.rate = rate;
this.isBooked = false;
}
public void Book() {
System.out.println("Room " + this.number + " has successfully been booked.");
this.isBooked = true;
}
// This method "releases" the booking on the room by setting the instance variable isBooked to false
public void Release() {
System.out.println("Room " + this.number + " has successfully been released.");
this.isBooked = false;
}
// Print basic info about the current Room objects state
public void printRoomInfo() {
String state;
if (this.isBooked == true) {
state = "Unavailable";
}
else {
state = "Available";
}
System.out.println("Room " + this.number + " is a " + this.type + ". Rate is: " + this.rate + "$ per night. " + state + ".");
}
public void setRate(int newRate) {
this.rate = newRate;
}
}
Ваша программа работает отлично для меня, вы поместили весь код в один файл? –
Yup, это один класс верхнего уровня для каждого файла. –
@RobertMoskal В файле может быть только один «общедоступный» класс. Поэтому вы должны либо сделать все классы, кроме «HotelManagement» непубличными, либо следовать приведенному ниже ответу. – Prudhvi