File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Inheritance Problem/ Replace String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Inheritance Problem/ Replace String" Watch "Inheritance Problem/ Replace String" New topic

Inheritance Problem/ Replace String

Ron Ingram
Ranch Hand

Joined: Mar 11, 2011
Posts: 73
Working on my CS class assignment and have hit a road block...

Add a class FillInQuestion to the question hierarchy of How To 10.1. An object of this class is constructed with a string that contains the answer, surrounded by _ _, for example, "The inventor of Java was _James Gosling_". The question should be displayed as

The inventor of Java was _____

So, I've managed to split the string and store the right answers correctly. Also, I've been able to conjoin the _ _ to make the blank. My problem is the tester (QuestionDemo) passes the question containing _James Gosling_ to the FillInQuestion constructor which automatically calls super (Question) and passes the argument. All of my logic to handle the string is after it passes it to the Question constructor.. I need to be able to split the string and then pass to the Question constructor... Not sure how

Question Class (Parent)

FillInQuestion class


dennis deems
Ranch Hand

Joined: Mar 12, 2011
Posts: 808
It looks to me as if everything you need done is already happening in the FillInQuestion constructor. It creates the masked String, but then it doesn't do anything with it. You could either assign it to the superclass's text field, or override the superclass display method.
Ron Ingram
Ranch Hand

Joined: Mar 11, 2011
Posts: 73
Thanks... a simple override display() to include a new System.out.println(temp3) was all it took...
I agree. Here's the link:
subject: Inheritance Problem/ Replace String
jQuery in Action, 3rd edition