OOD problem.

Hi there i am currently working on a project for college. I have created a series of class programs for a hotel chain (hotel, booking, and customer etc.) and create a main class that populates the classes and showes them running. So far so good.

The next part of my project requires me to create a class for a country club which i have done making it a subclass of hotel but i keep getting an error:

')' expected

I have went through the code and it seems ok can anyone see any mistakes.

import javax.swing.*;

publicclass COUNTRYextends HOTEL{

//instance variables

privateint golf,gym,tennis;

public COUNTRY(){}//empty constructor

public COUNTRY(String name, String location, String manager,int size,int star,int golf,int gym,int tennis){

super(String name, String location, String manager,int size,int star);

setGolf(golf);

setGym(gym);

setTennis(tennis);

}

public String toString(){

String output;

output=super.toString();

output=output+"The country club has "+this.golf+" golf courses."+"\n";

output=output+"The country club has "+this.gym+" gyms"+"\n";

output=output+"The country club has "+this.tennis+" tennis courts"+"\n";

return output;

}

publicvoid printDetails(){

String output;

output = toString();

//display message

JOptionPane.showMessageDialog(null, output,"Details of Country club", JOptionPane.INFORMATION_MESSAGE);

}

//set methods

privatevoid setGolf (int golf){

this.golf=golf;

}

privatevoid setGym (int gym){

this.gym=gym;

}

privatevoid setTennis (int tennis){

this.tennis=tennis;

}

}//end class

[3555 byte] By [gerry2805a] at [2007-11-26 13:10:20]
# 1

// change this...

super(String name, String location, String manager, int size, int star);

// to this...

super(name, location, manager, size, star);

One shouldn't attempt to declare variable types in a constructor call.

~

yawmarka at 2007-7-7 17:24:24 > top of Java-index,Java Essentials,New To Java...
# 2

> super(String name, String location, String manager, int size, int star);

Invalid syntax. You're invoking the super constructor here, not declaring one.

super(name, location, ...);

Lose the declarations of the parameter types.

Think about it. You wrote this line correctly:

> setGolf(golf);

You didn't write

setGolf(int golf);

there did you?

warnerjaa at 2007-7-7 17:24:24 > top of Java-index,Java Essentials,New To Java...
# 3
Post the completed error message, and point out the line it complains about.Don't have class names in all caps. Use CamelCase.
mlka at 2007-7-7 17:24:24 > top of Java-index,Java Essentials,New To Java...
# 4
why is country club a subclass of hotel?
georgemca at 2007-7-7 17:24:24 > top of Java-index,Java Essentials,New To Java...
# 5

that seems to have fixed the errors on that class. When i run the class with the main function though it is giving me a new error

public class DemoCountry {

public static void main(String argv[]) {

//creates a Country Object

COUNTRY c1 = new COUNTRY ("Gerrys Hotel","Well Park","John",150,32,1,1);

//print details

c1.printDetails();

System.exit(0);

}

}

cannot find symbol constructor COUNTRY(java.lang.String.java.lang.String.java.lang.String,int,int,int,int)

The error looks like the object i am creating doesn't match the parameters ofmy constructor i have in COUNTRY. I cant see any differences but i am quite new to promming and am just working from a manual a friend gave me.

gerry2805a at 2007-7-7 17:24:24 > top of Java-index,Java Essentials,New To Java...
# 6
Your COUNTRY constructor with parameters requires five int values in addition to the three String references.~
yawmarka at 2007-7-7 17:24:24 > top of Java-index,Java Essentials,New To Java...
# 7

> Hi there i am currently working on a project for

> college. I have created a series of class programs

> for a hotel chain (hotel, booking, and customer etc.)

> and create a main class that populates the classes

> and showes them running. So far so good.

>

> The next part of my project requires me to create a

> class for a country club which i have done making it

> a subclass of hotel but i keep getting an error:

>

> ')' expected

>

> I have went through the code and it seems ok can

> anyone see any mistakes.

>

> [code]import javax.swing.*;

>

> public class COUNTRY extends HOTEL{

>

Do you really think that there is a valid inheritance relationship here. Do you think you are fulfilling LSP or you are extending for the sake of it.

Class Inheritance is the most abused feature of Java please avoid it if you can. Am mentioning this since you seem to be concerned about the OOD

kilyasa at 2007-7-7 17:24:24 > top of Java-index,Java Essentials,New To Java...
# 8

> > Hi there i am currently working on a project for

> > college. I have created a series of class programs

> > for a hotel chain (hotel, booking, and customer

> etc.)

> > and create a main class that populates the classes

> > and showes them running. So far so good.

> >

> > The next part of my project requires me to create

> a

> > class for a country club which i have done making

> it

> > a subclass of hotel but i keep getting an error:

> >

> > ')' expected

> >

> > I have went through the code and it seems ok can

> > anyone see any mistakes.

> >

> > [code]import javax.swing.*;

> >

> > public class COUNTRY extends HOTEL{

> >

>

> Do you really think that there is a valid inheritance

> relationship here. Do you think you are fulfilling

> LSP or you are extending for the sake of it.

>

> Class Inheritance is the most abused feature of Java

> please avoid it if you can. Am mentioning this since

> you seem to be concerned about the OOD

I bet you a zillion space dollars it's because Hotel has some methods that the OP wants to reuse in Country :-/

georgemca at 2007-7-7 17:24:24 > top of Java-index,Java Essentials,New To Java...
# 9

> I bet you a zillion space dollars it's because Hotel

> has some methods that the OP wants to reuse in

> Country :-/

Bingo!. and thats why I am always against using inheritance for the sake of code reusability. It would not only make the code hard to maintain but impossible to extend. Refer to open closed principle

kilyasa at 2007-7-7 17:24:24 > top of Java-index,Java Essentials,New To Java...
# 10

> Do you really think that there is a valid inheritance relationship here.

Perhaps the author's design describes a country club as a special kind of hotel, with some extended functionality. I don't see that there's not a good reason for inheritance at this point.

~

yawmarka at 2007-7-7 17:24:24 > top of Java-index,Java Essentials,New To Java...
# 11

> > Do you really think that there is a valid

> inheritance relationship here.

>

> Perhaps the author's design describes a country club

> as a special kind of hotel, with some extended

> functionality. I don't see that there's not a

> good reason for inheritance at this point.

>

> ~

but is a country club a specialized hotel? I honestly don't know, we don't have them where I'm from

georgemca at 2007-7-7 17:24:24 > top of Java-index,Java Essentials,New To Java...
# 12

> but is a country club a specialized hotel?

It may be for the purposes of this application. It also may not. Either way, I don't think there's enough information to say the design is stinky* at this point. But that's just my opinion, of course. :o)

* A refactoring to a new name seems to be in order, though...

~

yawmarka at 2007-7-7 17:24:24 > top of Java-index,Java Essentials,New To Java...
# 13
i had 4 int there was 5 in the con. im not getting any better at spotting these things . thanks
gerry2805a at 2007-7-7 17:24:24 > top of Java-index,Java Essentials,New To Java...
# 14

> > but is a country club a specialized hotel?

>

> It may be for the purposes of this application. It

> also may not. Either way, I don't think there's

> enough information to say the design is stinky* at

> this point. But that's just my opinion, of course.

> :o)

>

> * A refactoring to a new name seems to be in order,

> though...

>

> ~

Now I may sound a bit too theoretical over here, and a lot of you might find it just aesthetics for discussion purposes but, the question is not only is the country club a specialized form of a hotel, but it is any extensions down the road of the COuntry club, would it make the code open for modification, which is a big no no. Secondly does it follow :-

if S is a subtype of T, then objects of type T in a program may be replaced with objects of type S without altering any of the desirable properties of that program (e.g., correctness).

IMHO, it does not, but then its just me, and I can be wrong a lot of times ;)

kilyasa at 2007-7-7 17:24:24 > top of Java-index,Java Essentials,New To Java...
# 15

> > Do you really think that there is a valid

> inheritance relationship here.

>

> Perhaps the author's design describes a country club

> as a special kind of hotel, with some extended

> functionality. I don't see that there's not a

> good reason for inheritance at this point.

>

I take the point that unless one can demonstrate postively that inheritance is needed then it shouldn't be.

So it wouldn't be a matter of whether it could be but rather why it must be.

jschella at 2007-7-21 15:46:19 > top of Java-index,Java Essentials,New To Java...
# 16
> but is a country club a specialized hotel?Any country club which has lodging facilities is going to have more than just one business unit. It would have lodging, shops, restaurants, etc.The country club would need to own all of the business units and not be one of them.
jschella at 2007-7-21 15:46:19 > top of Java-index,Java Essentials,New To Java...