Jump to content

building on previous classes?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
hayschooler

hayschooler

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
I'm working on a program with a class that builds a room, another class the builds a floor of rooms and another that creates a building from the floors. I'm just kind of lost with using the previous using the previous classes to build my new class upon. I'm not sure if I'm calling and setting things properly. Can someone tell me what I should be looking for with the errors I have. Do I have to go back and add additional setters and getters in the previous classes? I posted my error messages below.


[FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]
1 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]import[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] java.awt.*;
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]2 
3 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]class[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] Building [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]extends[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] Floor
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]4 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]{
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]5 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]private[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] numfloors;
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]6 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]7 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]8 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]void[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] draw(Graphics page)
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]9 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]{ 
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]10 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]page.setColor(color);
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]11 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]for[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] ([/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] f = 1; f <= numfloors; f++)
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]12 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]{
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]13 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]for[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] ([/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] r = 1; r <= [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].getRooms; r++)
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]14 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]{
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]15 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].draw(page);
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]16 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setX([/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].getX() + [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].getLength()); 
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]17 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]}
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]18 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]} 
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]19 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]}
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]20 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]21 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]22 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] Building()
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]23 
24 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]{
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]25 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]numfloors = 5; 
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]26 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]numrooms = 1;
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]27 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setX(0);
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]28 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setY(0);
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]29 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setLength(50);
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]30 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setColor(Color.black);
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]31 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]}
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]32 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]33 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] Building([/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] rows, [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] num, [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] size, [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] x, [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] y, Color clr)
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]34 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]{
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]35 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]numfloors = rows;
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]36 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setRooms(rms);
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]37 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setX(x-size*(num));
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]38 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setY(y);
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]39 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setLength(size);
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]40 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setColor(clr); 
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]41 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]}
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]42 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]43 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]void[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] setX([/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] x)
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]44 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]{
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]45 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setX(x);
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]46 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]}
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]47 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]48 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]void[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] setY([/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] y)
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]49 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]{
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]50 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setY(y);
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]51 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]}
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]52 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]53 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]void[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] setLength([/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] len)
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]54 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]{
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]55 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setLength(len);
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]56 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]}
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]57 
58 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]void[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] setRooms([/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] rms)
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]59 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]{
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]60 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setRooms(rms) = rms;
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]61 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]}
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]62 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]63 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]void[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] getRooms([/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] rms)
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]64 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]{
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]65 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setRooms(rms) = rms;
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]66 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]}
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]67 
68 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] getY()
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]69 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]{
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]70 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]return[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].getY();
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]71 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]}
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]72 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]73 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] getX()
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]74 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]{
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]75 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]return[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].getX();
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]76 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]}
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]77 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]}
[/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff][/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][/FONT]

ÏBuilding.java:13: cannot find symbol
ÏϧÏsymbol : variable getRooms
ÏϧÏlocation: class Floor
ÏÏ§Ï for (int r = 1; r <= super.getRooms; r++)
ÏÏ§Ï ^
ϼ§ÏBuilding.java:36: cannot find symbol
ÏϧÏsymbol : variable rms
ÏϧÏlocation: class Building
ÏÏ§Ï super.setRooms(rms);
ÏÏ§Ï ^
ϼ§ÏBuilding.java:60: cannot find symbol
ÏϧÏsymbol : method setRooms(int)
ÏϧÏlocation: class Floor
ÏÏ§Ï super.setRooms(rms) = rms;
ÏÏ§Ï ^
ϼ§ÏBuilding.java:65: cannot find symbol
ÏϧÏsymbol : method setRooms(int)
ÏϧÏlocation: class Floor
ÏÏ§Ï super.setRooms(rms) = rms;
ÏÏ§Ï ^
ÏϧÏ4 errors



#2
tate

tate

    Learning Programmer

  • Members
  • PipPipPip
  • 90 posts
You don't have to remake all of the extended class's methods. Here is a simple example. Say we have class A:
public class A {
    
    private int a;
    
    public A(int a){
        this.a=a;
    }
    
    public void setA(int a){
        this.a=a;
    }
    
    public int getA(){
        return this.a;
    }
}
And we want to extend it with class B:
public class B extends A{
    
    private int b;
    
    public B(int a, int b){
        super(a);
        this.b=b;
    }
    
    public void setB(int b){
        this.b=b;
    }
    
    public int getB(){
        return this.b;
    }
    
    public int multiply(){
        return this.getA()*this.getB();
    }
    
    //Override class A's setA method to make it square the given int
    public void setA(int a){
        super.setA(a*a);
    }
    
    public static void main(String args[]){
        B f = new B(3,4);
        f.setA(f.getA());
        System.out.println("A = "+f.getA());
        System.out.println("B = "+f.getB());
        System.out.println("A*B = "+f.multiply());
    }
}
You only need to override a method from an extended class if you want to change something it does. Hope this helps.
twas brillig

#3
hayschooler

hayschooler

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
Sorry, Maybe still not understanding. I didn't really think I was overriding anything. I've never used overriding so maybe I don't understand where it's appropriate to use. I'm not changing any of the methods but just adding an additional feature.

My previous class which gives the ability to draw a floor of rooms needs to access the room class. Doesn't it have to remake all of the extended classes methods to get them set from the parameters needed to create a building? I'm giving it the parameters so it can go backwards and build the room first. Then it will know how to build a floor full of the rooms. My logic is probably wrong but I don't know how to think of how uses the previous classes to create something new?

Wouldn't wee need these setters and getters to set the properties in the previous class and then be able to call them with the getters. I was trying to do that with my building class so I can send the parameters from the building back to the floor so I can start with a room. Again, sorry if I have this logic wrong.

This is how the floor class was rubuilding the room.

[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] Floor([/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] num, [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] x, [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] y, [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] size, Color clr)[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New]numrooms = num;[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setX(x-size*(num));[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setY(y);[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setLength(size);[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setColor(clr);[/FONT]
[FONT=Courier New]}[/FONT]
 
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]void[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] setX([/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] x)[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setX(x);[/FONT]
[FONT=Courier New]}[/FONT]
 
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]void[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] setY([/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] y)[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setY(y);[/FONT]
[FONT=Courier New]}[/FONT]
 
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]void[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] setLength([/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] len)[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setLength(len);[/FONT]
[FONT=Courier New]}[/FONT]
 
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] getY()[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]return[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].getY();[/FONT]
[FONT=Courier New]}[/FONT]
 
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] getX()[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]return[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].getX();[/FONT]
[FONT=Courier New]}[/FONT]
 

Edited by hayschooler, 09 May 2010 - 05:39 PM.


#4
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
He mentioned you didn't need to override everything because of
publicvoid setX(int x)
{
super.setX(x);
}

publicvoid setY(int y)
{
super.setY(y);
}

publicvoid setLength(int len)
{
super.setLength(len);
}

publicint getY()
{
returnsuper.getY();
}

There's no need to do that. If Java doesn't find a method getY() in the current class, it will automatically use that method from the super class if it exists there.
Because of this you can always do .toString() on anything because the class Object has that method and every other class extends Object.

Also, if you extend another class, the first line of the constructor MUST call the constructor of the super class. So if Building extends Floor, the first line in the constructor of Building must be super().
super() will call the constructor of Floor. (If the constructor of Floor takes requires parameters you obviously give them with the super.
like:
22 public Building()
23 
24 {
     super(0,0,50,Color.black);
25 numfloors = 5; 
26 numrooms = 1;
31 }


Example from http://java.sun.com/...subclasses.html in case my explanation wasn't very clear ^^
public class Bicycle {
	
    // the Bicycle class has three fields
    public int cadence;
    public int gear;
    public int speed;
	
    // the Bicycle class has one constructor
    [COLOR="red"][B]public Bicycle(int startCadence, int startSpeed, int startGear) {[/B][/COLOR]
        gear = startGear;
        cadence = startCadence;
        speed = startSpeed;
    }
	
    // the Bicycle class has four methods
    public void setCadence(int newValue) {
        cadence = newValue;
    }
	
    public void setGear(int newValue) {
        gear = newValue;
    }
	
    public void applyBrake(int decrement) {
        speed -= decrement;
    }
	
    public void speedUp(int increment) {
        speed += increment;
    }
	
}

public class MountainBike [COLOR="red"][B]extends Bicycle [/B][/COLOR]{
	
    // the MountainBike subclass adds one field
    public int seatHeight;

    // the MountainBike subclass has one constructor
    public MountainBike(int startHeight, int startCadence, int startSpeed, int startGear) {
        [COLOR="red"][B]super(startCadence, startSpeed, startGear);[/B][/COLOR]
        seatHeight = startHeight;
    }	
	
    // the MountainBike subclass adds one method
    public void setHeight(int newValue) {
        seatHeight = newValue;
    }	

}


#5
hayschooler

hayschooler

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
oxano, thanks I've made some progress. The program actually compiles now though it displays incorrectly. I think the problem is with my loop since my building is building horizontally rather than vertically. Beyond that though, a misunderstanding I have is when you pass the parameters to the constructor don't the parameters have to be in the right sequence to assume the correct value for the respective variables? Does the the parameter called rows which I've passed which is first in the sequence still get assigned to the numrows variable which is now underneath the call to super ?

This is how my object is created and the first parameter is the number of floors that I want my building to be:

[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]import[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] javax.swing.*;[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]import[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] java.awt.*;[/FONT]
 
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]class[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] BuildingPanel [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]extends[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] JPanel[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New]Building bld = [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]new[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] Building(5, 2, 460, 350, 50, Color.yellow);[/FONT]
[FONT=Courier New][COLOR=#fa6400][FONT=Courier New][COLOR=#fa6400]//Building bld2 = new Building(5, 1, 200, 350, 50, Color.red);[/COLOR][/FONT]
[/COLOR][/FONT]
 
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] BuildingPanel()[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New]setPreferredSize ([/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]new[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] Dimension(800, 600));[/FONT]
[FONT=Courier New]setBackground (Color.white);[/FONT]
[FONT=Courier New]}[/FONT]
 
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]void[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] paintComponent (Graphics page)[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].paintComponent(page);[/FONT]
[FONT=Courier New]bld.draw(page);[/FONT]
[FONT=Courier New][COLOR=#fa6400][FONT=Courier New][COLOR=#fa6400]// bld2.draw(page);[/COLOR][/FONT]
[/COLOR][/FONT][FONT=Courier New]}[/FONT]
[FONT=Courier New]}[/FONT]
 

This is my constructor which recieves the parameters from the new object but doesn't it assign rows first?

[FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]33 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] Building ([/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] rows, [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] num, [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] size, [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] x, [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] y, Color clr)[/FONT]
[FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]34 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]{[/FONT]
[FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]35 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New](num, size, x, y, clr);[/FONT]
[FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]36 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]numfloors = rows;[/FONT]
[FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]37 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]}[/FONT]
[FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]38 [/COLOR][/FONT][/COLOR][/FONT]
[FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]39 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]void[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] setRows([/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] rows) [/FONT]
[FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]40 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]{[/FONT]
[FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]41 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]numfloors = rows;[/FONT]
[FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]42 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]} [/FONT]
[FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]43 [/COLOR][/FONT]
[FONT=Courier New][COLOR=#0000ff]44 [/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]}[/FONT]


The example from which I was originally working off and why I was confused showed the base or room class like this. The instructions told me to study their example and then to build my building class as they had extended their floor class from room. This is the base class Room.

[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]class[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] Room[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]protected[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] length;[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]protected[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] x_pos;[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]protected[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] y_pos;[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]protected[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] Color color;[/FONT]
 
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] Room()[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New]length = 100;[/FONT]
[FONT=Courier New]x_pos = 100;[/FONT]
[FONT=Courier New]y_pos = 100;[/FONT]
[FONT=Courier New]color = Color.green;[/FONT]
[FONT=Courier New]}[/FONT]
 
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] Room([/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] len, [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] x, [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] y, Color colr)[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New]length = len;[/FONT]
[FONT=Courier New]x_pos = x;[/FONT]
[FONT=Courier New]y_pos = y;[/FONT]
[FONT=Courier New]color = colr;[/FONT]
[FONT=Courier New]}[/FONT]
 
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]void[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] setColor(Color colr)[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New]color = colr; [/FONT]
[FONT=Courier New]}[/FONT]
 
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]void[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] setLength([/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] len)[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New]length = len;[/FONT]
[FONT=Courier New]}[/FONT]
 
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]void[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] setX([/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] x)[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New]x_pos = x;[/FONT]
[FONT=Courier New]}[/FONT]
 
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]void[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] setY([/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] y)[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New]y_pos = y;[/FONT]
[FONT=Courier New]}[/FONT]
 
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] getLength()[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]return[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] length;[/FONT]
[FONT=Courier New]}[/FONT]
 
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] getX()[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]return[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] x_pos;[/FONT]
[FONT=Courier New]}[/FONT]
 
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] getY()[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]return[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] y_pos;[/FONT]
[FONT=Courier New]}[/FONT]
 
 
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]void[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] draw(Graphics page)[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New]page.setColor(color);[/FONT]
[FONT=Courier New]page.fillRect(x_pos, y_pos, length, length/2);[/FONT]
[FONT=Courier New]page.setColor(Color.gray);[/FONT]
[FONT=Courier New]page.fillRect(x_pos+length/3, y_pos+length/8, length/3, length/4);[/FONT]
[FONT=Courier New]}[/FONT]
[FONT=Courier New]}[/FONT]

When they extended it to the floor class they didn't show the call to super as the first line in the constructor as your example shows. I was trying to model my extension of Floor to Building as was done in this extension of Room to Floor.

[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]class[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] Floor [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]extends[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] Room[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]protected[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] numrooms;[/FONT]
 
 
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]void[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] draw(Graphics page)[/FONT]
[FONT=Courier New]{ [/FONT]
[FONT=Courier New]page.setColor(color);[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]for[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] ([/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] r = 1; r <= numrooms; r++)[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].draw(page);[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setX([/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].getX() + [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].getLength()); [/FONT]
[FONT=Courier New]} [/FONT]
[FONT=Courier New]}[/FONT]
 
 
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] Floor()[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New]numrooms = 1;[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setX(0);[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setY(0);[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setLength(50);[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setColor(Color.black);[/FONT]
[FONT=Courier New]}[/FONT]
 
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] Floor([/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] num, [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] x, [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] y, [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] size, Color clr)[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New]numrooms = num;[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setX(x-size*(num));[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setY(y);[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setLength(size);[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setColor(clr);[/FONT]
[FONT=Courier New]}[/FONT]
 
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]void[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] setX([/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] x)[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setX(x);[/FONT]
[FONT=Courier New]}[/FONT]
 
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]void[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] setY([/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] y)[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setY(y);[/FONT]
[FONT=Courier New]}[/FONT]
 
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]void[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] setLength([/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] len)[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].setLength(len);[/FONT]
[FONT=Courier New]}[/FONT]
 
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] getY()[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]return[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].getY();[/FONT]
[FONT=Courier New]}[/FONT]
 
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]int[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] getX()[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]return[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]super[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New].getX();[/FONT]
[FONT=Courier New]}[/FONT]
 
[FONT=Courier New]}[/FONT]