Thread View: pl.comp.lang.java
2 messages
2 total messages
Started by R T Sreeram
Mon, 17 Feb 1997 23:46
PLEASE help a beginner
Author: R T Sreeram
Date: Mon, 17 Feb 1997 23:46
Date: Mon, 17 Feb 1997 23:46
82 lines
3274 bytes
3274 bytes
PLEASE HELP NEEDED FOR BEGINNER : E_mail your response to:
enprts@bath.ac.uk
---------------------------------------------------------
Hi,
I am a novice in Java and I am trying to run a java
application from a book
by Peter Norton's guide to Java programming (pages 225-226):
Here is the code.
---------------------------------------------------------
public class Bldg{
static String heatType;
public static void main (String args[]) {
int height, width, depth, lotsize;
}
public String getHeatType () {
return(heatType);
}
}
public class AptBldg extends Bldg {
int numApts;
Apt apt[];
public int findVacatApt () {
int i;
for (i = 0; i < numApts; i++) {
if (apt[i].isVacant == true) {
return(i);
}
}
return(-1);
}
}
public class Apt {
boolean vacant;
int aptNumber;
public boolean isVacant() {
return(vacant);
}
}
public class AptMangaer{
public findEmptyApt (AptBldg aptbldg) {
int AptNum;
String heatType;
AptNum = aptBldg.findVacantApt();
if (AptNum > 0) {
heatType = aptBldg.getHeatType();
System.out.println("Apartment"+AptNum+"is available for rent");
System.out.println("Type of heat is " + heatType);
}
}
}
---------------------------------------------------------------------
The book says that this program is to demonstarate the concept of
inheritance. Now, when I try to compile the code, I get the
following error:
---------------------------------------------------------------------
AptManager.java:1: 'class' or 'interface' keyword expected.
public AptMangaer {
^
AptManager.java:2: Invalid method declaration; return type required.
public findEmptyApt (AptBldg aptbldg) {
^
AptManager.java:1: Warning: Public class AptMangaer must be defined in a
file called "AptMangaer.java".
public AptMangaer {
^
AptBldg.java:7: Attempt to reference method isVacant in class Apt as an
instance variable.
if (apt[i].isVacant == true) {
-----------------------------------------------------------------------
It would be of great help if anyone can advise me where have I gone
wrong. Thanks in advance for your time.
CR
e-mail : enprts@bath.ac.uk
Re: PLEASE help a beginner
Author: Gerry Buzzell
Date: Tue, 18 Feb 1997 22:34
Date: Tue, 18 Feb 1997 22:34
29 lines
1692 bytes
1692 bytes
gbuzzell@cybercom.net [Gerry Buzzell] wrote:
You have a misspelled word and the dumb computer is being nitty.
The first error is generally the important one. The rest are just
results of the first.
See below:
--- snip ---
> public boolean isVacant() {
> return(vacant);
> }
>}
>
>public class AptMangaer{
-------------------------------^
should be AptManager
>public findEmptyApt (AptBldg aptbldg) {
>int AptNum;
--- snip ---
>---------------------------------------------------------------------
>The book says that this program is to demonstarate the concept of
>inheritance. Now, when I try to compile the code, I get the
>following error:
>---------------------------------------------------------------------
>AptManager.java:1: 'class' or 'interface' keyword expected.
>public AptMangaer {
--- snip ---
Gerry
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads