This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.
We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

TestOrder.java

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi there, the following issue builds somewhat on my previous issues with TestPizza.java:

https://coderanch.com/t/726873/java/TestPizza-java#3380193


This next program, TestOrder.java , should output the name of the customer and an array of the pizzas that they have ordered, which is pulled from the Order class.

However, none of the parameters in my order objects are being resolved to a variable. What do I need to do to fix this? The pizza objects to be used as items in the arrays are defined in TestPizza.java 's main method. It seems they are not in scope, but it is a public method so I don't see why they shouldn't be.

Code for the Order class:




and the code for the Main Method:





code for TestPizza.java:

 
Rancher
Posts: 4453
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the errors you get when you compile this?

And your TestPizza code has nothing at all to do with your TestOrder code.
 
Charles Ormond
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:Where is the class Pizza defined?



Pizza is defined in Pizza.java here:

 
Charles Ormond
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:Can you post the errors you get when you compile this?

And your TestPizza code has nothing at all to do with your TestOrder code.



joeBloggs cannot be resolved to a variable
       meatPizza cannot be resolved to a variable
       hawaiianPizza cannot be resolved to a variable
       theresaGreen cannot be resolved to a variable
       hawaiianPizza cannot be resolved to a variable
       hawaiianPizza cannot be resolved to a variable
       robinCrook cannot be resolved to a variable
       pepperoniPizza cannot be resolved to a variable
       pepperoniPizza cannot be resolved to a variable
 
Carey Brown
Saloon Keeper
Posts: 6796
64
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where have you defined the class Customer and where have you created the Customer object joeBloggs?
 
Sheriff
Posts: 14768
245
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is in your TestOrder.main. The Order constructor takes an array of Pizza. You're trying to pass in a array of String. Also, the things that are in the arary you're creating are not defined.
 
Charles Ormond
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:Where have you defined the class Customer and where have you created the Customer object joeBloggs?



Customer.java

 
Carey Brown
Saloon Keeper
Posts: 6796
64
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Charles Ormond wrote:

Carey Brown wrote: and where have you created the Customer object joeBloggs?

 
Charles Ormond
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:

Charles Ormond wrote:

Carey Brown wrote: and where have you created the Customer object joeBloggs?



In the main method of TestCustomer.java:


 
Dave Tolls
Rancher
Posts: 4453
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, that's the disconnect.

Your TestCustomer, TestPizza and TestOrder classes are all entirely separate things.
The stuff declared in the main method in each of them is not visible by the others.

They are, essentially, different programs.
 
Charles Ormond
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:Ah, that's the disconnect.

Your TestCustomer, TestPizza and TestOrder classes are all entirely separate things.
The stuff declared in the main method in each of them is not visible by the others.

They are, essentially, different programs.



If they are all public classes in the same folder, then why does that matter?
 
Junilu Lacar
Sheriff
Posts: 14768
245
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It matters to the Java compiler. All those variables you've define in their respective main() methods are local variables and are thus visible only in their respective main() methods. You don't want to start making them public either so that you can access them from anywhere. That would be a bad idea and violates the principle of encapsulation.
 
Marshal
Posts: 67533
257
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, did you get the Pizza problem corrected? Have you tested Pizzas to see how they run?
 
Charles Ormond
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:By the way, did you get the Pizza problem corrected? Have you tested Pizzas to see how they run?



yes, got that one sorted after a lot of playing around 👍
 
If you are using a wood chipper, you are doing it wrong. Even on this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!