i'm trying make class called roombase
, has abstract method , 2 attributes, need make program work roombase
class inherits getroomdetailsfromuser()
in room
class.
roombase
class:
public abstract class roombase { public abstract void getroomdetailsfromuser(); private int roomnumber; private int numberofseats; }
room
class:
public abstract class room implements bookable { scanner input = new scanner(system.in); private static int roomnumber; private static int numberofseats; private static string reservedby = ""; private static boolean reserved; private static boolean hassmartboard; /** * attribute values user. */ public room(int roomnumber) { this.roomnumber = roomnumber; } public void getroomdetailsfromuser() { system.out.print("enter number of seats: "); numberofseats = input.nextint(); input.nextline(); system.out.print("does classroom have smart board? (y/n)"); hassmartboard = input.nextline().equalsignorecase("y"); } public boolean ishassmartboard() { return hassmartboard; } public void sethassmartboard(boolean hassmartboard) { this.hassmartboard = hassmartboard; } public static int getnumberofseats() { return numberofseats; } public void setnumberofseats(int numberofseats) { this.numberofseats = numberofseats; } public string getreservedby() { return reservedby; } public void setreservedby(string reservedby) { this.reservedby = reservedby; } public boolean isreserved() { return reserved; } public void setreserved(boolean reserved) { this.reserved = reserved; } public int getroomnumber() { return roomnumber; } /** * update room reserved , reserved by. */ public void reservethisroom(){ this.reserved = true; system.out.println("enter name of person reserving room: "); reservedby = input.nextline(); } /** * update room not reserved , clear reserved by. */ public void releasethisroom(){ this.reserved = false; reservedby = ""; system.out.println("room has been released\n"); } public string tostring() { string output = "\n\n******************************" + "\nroom number: " + roomnumber + "\nnumber of seats: " + numberofseats + "\nreserved by: " + reservedby + "\nreserved: " + reserved + "\nsmart board: "+ hassmartboard; return output; } }
i think have think little bit more on design implementation, let's see example class hierarchy be, , important, why.
does makes sense roombase extends or gets logic room class, should not other way around ? roombase base class? if getroomdetailsfromuser
method's logic should common or base code not instead on base class in specific class (room in case), , finish, need abstract class here @ all? or regular base class fulfill needs ?
check design , let me know if can further.
Comments
Post a Comment