Forums Register Login

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

+Pie Number of slices to send: Send
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()
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 

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()

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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..


+Pie Number of slices to send: Send
This is an error in the book. Please correct it in your book

Does this tiny ad smell okay to you?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1626 times.
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
Compiling errata for K&B, SCJP 6
Private Variable in an Enum
Miscellaneous Doubts
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 01:47:01.