Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

TestOrder.java

 
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Saloon Keeper
Posts: 9566
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9566
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where have you defined the class Customer and where have you created the Customer object joeBloggs?
 
Sheriff
Posts: 17150
298
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9566
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

Charles Ormond wrote:

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

 
Charles Ormond
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 17150
298
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 76479
366
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 👍
 
My honeysuckle is blooming this year! Now to fertilize this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic