• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

print from two different classes problem

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i want to be able to write to a text file variables from two different classes

I have a toString (delimiter) method that accepts input from the first class and i need a way to accept input from the second class as well.. i have printWriter printing the toString(delimiter) method
 
Saloon Keeper
Posts: 9563
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want a single file then use a single printWriter.

BTW, you are starting WAY too many topics for the same project and, like this post, unless you've looked at the others you've got no context. PLEASE stop creating new topics for this project.
 
Georgios Adamidis
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:If you want a single file then use a single printWriter.

BTW, you are starting WAY too many topics for the same project and, like this post, unless you've looked at the others you've got no context. PLEASE stop creating new topics for this project.


how do i add the second class within the same print object? sorry i wont create any more topics this is my last problem
 
Georgios Adamidis
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:If you want a single file then use a single printWriter.

BTW, you are starting WAY too many topics for the same project and, like this post, unless you've looked at the others you've got no context. PLEASE stop creating new topics for this project.


i managed to add the variables from the second class however they get printed with default values
for instance my reviewer object gets printed "TBC" instead of John as was the input.. my rating object gets printed 0 instead of 3 as i set it

the following bit  of code sets them as they were printed which means that the problem is when i try to input the values the variables get no input

here is my code where i'm trying to input the values
 
Rancher
Posts: 4888
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code needs to use the existing instance of the class that has the desired data.  If new instances are created, the values in the existing instance will not be available.

The reference to the existing instance needs to  be passed to all the places where it is needed.
 
Sheriff
Posts: 7113
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think we're going to need to see more code from Review, specifically setRatings() and setReviewer();
 
Georgios Adamidis
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:I think we're going to need to see more code from Review, specifically setRatings() and setReviewer();


 
Knute Snortum
Sheriff
Posts: 7113
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't need to return anything from your setXxx() methods, but they seem to be setting the fields just fine.  Now how are you using the Review class to pass the data?  Do you have getReviewer() and getRating() methods?
 
Georgios Adamidis
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:You don't need to return anything from your setXxx() methods, but they seem to be setting the fields just fine.  Now how are you using the Review class to pass the data?  Do you have getReviewer() and getRating() methods?


yes here they are

 
Carey Brown
Saloon Keeper
Posts: 9563
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The variable 'rev' is a local variable, and you are setting ratings and name, however, 'rev' is not the instance you are printing as it disappears (goes out of scope) when this method returns.
 
You had your fun. Now it's time to go to jail. Thanks for your help tiny ad.
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic