wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Sun Ceritified Programmer for Java 6 Study Guide chapter-3 & question-7 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Sun Ceritified Programmer for Java 6 Study Guide chapter-3 & question-7" Watch "Sun Ceritified Programmer for Java 6 Study Guide chapter-3 & question-7" New topic
Author

Sun Ceritified Programmer for Java 6 Study Guide chapter-3 & question-7

Sravani Duggirala
Greenhorn

Joined: May 06, 2009
Posts: 4
The following is the code for one of the questions in the Scjp study guide :
public class Bridge
{
public enum Suits
{
CLUBS(20),DIAMONDS(20),HEARTS(30),SPADES(30),
NOTRUMP(40){ public int getValue(int bid){
return ((bid-1)*30)+40;
} };
Suits(int points) { this.points=points;}
private int points;
public int getValue(int bid) { return points*bid; }
}
public static void main(String[] args)
{
System.out.println(Suits.NOTRUMP.getBidValue(3));
System.out.println(Suits.SPADES+ " "+Suits.SPADES.points);
System.out.println(Suites.values());
}
}


The options provided are :
A.The output could contain 30
B.The output could contain @bf73fa
C.The output could contain DIAMONDS
D.Compilation fails due to an error on line 6
E.Compilation fails due to an error on line 7
F.Compilation fails due to an error on line 8
G.Compilation fails due to an error on line 9
H.Compilation fails due to an error within lines 12 to 14


The answer is provided to be A and B.


But the above code should not Compile as there is no method named getBidValue()
Pushkar Choudhary
Rancher

Joined: May 21, 2006
Posts: 425

Hi Srvani, Welcome to JavaRanch!

Please Use Code Tags while posting any code here, since it becomes very difficult to read the code without them. You can click the "Edit" button and add them in your post above.


I checked the code that you have pasted here and there are a couple of compiler errors:
- There is no method named getBidValue().
- Not sure what is Suites in the last System.out.println() in the main method.

Assuming that you have posted the code correctly from the study guide, there seems to be an error in the guide.

But not sure what the correct answer would be, since the complier errors are on lines 15 and 17 in your code. However, none of the options provided for the answer seem to mention these line numbers.


-Pushkar
Sravani Duggirala
Greenhorn

Joined: May 06, 2009
Posts: 4
Sravani Duggirala wrote:The following is the code for one of the questions in the Scjp study guide :
public class Bridge
{
public enum Suits
{
CLUBS(20),DIAMONDS(20),HEARTS(30),SPADES(30),
NOTRUMP(40){ public int getValue(int bid){
return ((bid-1)*30)+40;
} };
Suits(int points) { this.points=points;}
private int points;
public int getValue(int bid) { return points*bid; }
}
public static void main(String[] args)
{
System.out.println(Suits.NOTRUMP.getBidValue(3));
System.out.println(Suits.SPADES+ " "+Suits.SPADES.points);
System.out.println(Suits.values());
}
}


The options provided are :
A.The output could contain 30
B.The output could contain @bf73fa
C.The output could contain DIAMONDS
D.Compilation fails due to an error on line 6
E.Compilation fails due to an error on line 7
F.Compilation fails due to an error on line 8
G.Compilation fails due to an error on line 9
H.Compilation fails due to an error within lines 12 to 14


The answer is provided to be A and B.


But the above code should not Compile as there is no method named getBidValue()
Sravani Duggirala
Greenhorn

Joined: May 06, 2009
Posts: 4
Hei Pushkar,

Thanks a lot for the comments...................I edited my message and now it doesn't seem to be violating the Java Ranch Protocol
Suites in line 14 is a typo from my side..........................and that was corrected...............so now the problem seems to be with the getBidValue() method.
Mumtaz Khan
Ranch Hand

Joined: Feb 21, 2008
Posts: 53
You are still not using code tags, you are referring to some line numbers but there is no line number in your code. please use code tags, it makes code readable.


SCJP 5.0 -- 97%
ashik chollangi
Greenhorn

Joined: Jun 06, 2008
Posts: 15
Hey I think this question is to test the knowledge in enums..
see there is getValue() methods this might be the gerBidValue() method which was being referred through main()

ok here if you change the name of getValue() to getBidValue() then we get 2 getBidValue() mehods..

the getBidValue() method on the line of NOTRUMP is just for NOTRUMP means..this NOTRUMP enum has overridden getBidValue() method in the same class for itself..



Im 4 Java
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

This is an error in the book. Please correct it in your book



SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sun Ceritified Programmer for Java 6 Study Guide chapter-3 & question-7
 
Similar Threads
Discussing errata for K&B, SCJP 6
K&B doubt(unofficial errata) Moderators,Please keep this thread on the top so all to see and add
Private Variable in an Enum
Miscellaneous Doubts
Compiling errata for K&B, SCJP 6