• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Resolving conflict between constructor and method call in main class

 
celine scarlett
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I've written a Title, TitleList and a main class to test these. The problem occurs between the constructors in the Title class and the test maim class. the constructors are as follows,

I need to call the above constructor in the test main class in conjunction with an add method from the TitleList class. The problem is that when the user runs the main class they have to input an integer and four strings. These strings can be any number of words per input.

How do I use the following main class with the above constructors?


Any idea how to use the user input of one integer and four strings with the constructors in the Title class?

Any help or advice gratefully appreciated!!
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming you lost this line in a typing this in ...

public Title( String filmDetails )

That constructor expects the five fields you have collected in one string with commas between them. Could you build one string like that from your fields?

The other constructor expects a SimpleReader that is ready to read the five fields in a single line. That could work, but you'd have to make sure your user is willing and able to type all five fields correctly with commas between them.

With either constructor, watch out for titles with commas in them! "The Good, the Bad and the Ugly" is going to be too complex for this program.

So try building one string from your five fields and show us how it goes!
 
celine scarlett
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for the help. I'm able to build one string from many using an example such as,

The problem is that I'm still getting errors from my main class. I get the following error,

These errors refer to the following code. Firstly within the Title class,

and secondly within the main class,

I'm assuming the second error is simply because of the first problem in the Title class.

Anybody know why this happening and what it means?
 
celine scarlett
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm happy to say I've nearly solved this problem. I now have the file being written and read correctly, up to the time the user inputs and saves the data on the third try. Then the previous line is saved with an extra comma after the first integer, as follows


Does anybody know why this might happen?

The current code for my main class is as follows,

Any help or advice?
 
Henry Wong
author
Marshal
Pie
Posts: 21437
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't look like an extra comma to me -- as all lines have the same amount of commas.

Henry
 
celine scarlett
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Yes, I think you're right. Whenever I try to add an extra title, it writes the first entry correctly, and then moves the first string to the second string postion in the list, leaving the first sting position empty, as follows,


Does anybody know why this might happen?
 
celine scarlett
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm very pleased to announce that this problem has finally been solved. I've added some extra code to the split method within the first constructor in the Title class. Code is as follows,

Thanks for all the help!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic