• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

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

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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()
 
Rancher
Posts: 425
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..


 
Sheriff
Posts: 9709
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is an error in the book. Please correct it in your book

 
reply
    Bookmark Topic Watch Topic
  • New Topic