• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Resolving conflict between constructor and method call in main class

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author
Posts: 23931
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
reply
    Bookmark Topic Watch Topic
  • New Topic