Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Sravani Duggirala
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 425
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
ashik chollangi
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..


 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is an error in the book. Please correct it in your book

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic