Friday, July 31, 2009

How might you .............. Java?

I am redoing a C++ program in java, Garage.java, which I haven't used in a while. It compiles, runs, but nothing pops up as it should, there is a JOptionPane in the 3rd function. My skeleton is as follows:





[imports]





public class Garage


{ /*Globals*/


/* What is the following for, I used to run the


functions in the main, but when i do that it says


non-static in static context or something like that?*/


public void Garage()


{


fillA();


print();


}





public void fillA()


{


/*Function 1 calls function 2*/


}


public void parkC()


{


/*JOPane*/


}


public static void main (String args[])


{


Garage application = new Garage(); //What is this?


System.exit(0);


}

How might you .............. Java?
Your class is 'Garage'.


'new Garage()' is the constructor call for a 'Garage'.


Your instance of 'Garage' is called 'application' (not a good name).


'public void Garage()' is NOT a constructor method (and not a good name for a method in 'Garage').


sooooooooooo


You need to call 'application.Garage()' after the constructor in 'main'.


orrrrrrrrrrrrrrr


You could change 'public void Garage()' to 'public Garage()' to make it a constructor method (which you already have a call to).
Reply:the first problem is "System.Exit(0);" closes the program.... and the constructor for garage should be "Public Garage()" not "public void Garage()"

flower garden

No comments:

Post a Comment