• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I get one program to take information out of another one.

 
Brandon Choate
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another day, another attempt at somehow trying to grasp the bare basics of this Java stuff.

Today's problem is this:

Program number one seems to work pretty well, no problems here:



... program number 2, however, is only half finished:



So, I'm trying to have the second program take all the methods from the previous program, and compute the value of a movie based off of that.

The problem lies with this: Viewer view = new Viewer();
It is in the same format as all the other programs I tried, but it says that it cannont find the second "Viewer" symbol. Why is this? It is written in the exact same style as similar programs of this type. What is different about this one?
This is the code that lets you take information from the "Viewer" program, right? If not, what is that code and why is the above line necessary?


Once I work that out, it should just be a question of calling up the methods like toString from the first program, right?
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This is the constructor for your Viewer class, it takes two Strings as arguments. In ViewerTest, you are trying to call a constructor with no parameters, but the viewer class doesn't have a constructor that takes no parameters. Either you'll have to add a constructor that takes no parameters to Viewer class, or supply some parameters when you call the constructor in ViewerTest.
 
Brandon Choate
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Garrett Rowe wrote:

This is the constructor for your Viewer class, it takes two Strings as arguments. In ViewerTest, you are trying to call a constructor with no parameters, but the viewer class doesn't have a constructor that takes no parameters. Either you'll have to add a constructor that takes no parameters to Viewer class, or supply some parameters when you call the constructor in ViewerTest.


Hmm, that seems to have helped a bit. Thanks!
 
Brandon Choate
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The more things change, the more they say the same:

Program 1:



... and program 2:




Now, when I input everything it throws out:

Enter a movie code A - F: A
Is the movie rare (R) or new (N)?: N
John D. 0 3.95
John D.



Only problems are that I want the "0" to be like AN or BN or FN.... and I want the 3.95 to change with the variables.
Its kinda like the inverse problem of what I had a few minutes ago.. I think.
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brandon Choate wrote:

Just a warning: in your constructor, you are shadowing the Customer and cost fields by a parameter and local variable respectively. In the end, you are never giving your instance fields any values.
You can fix this as follows:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic