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

need a snippet of code that modifies variables through a controller class

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
as mentioned above i am meant to design a project that writes restaurant reviews. There are two separate classes "Restaurant" and "Review". There is also a repository class and a controller class. i need a way to update the restaurant and reviews variables i have the following so far but it doesnt seem to be working.. any help is much appreciated
 
Marshal
Posts: 76479
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We need more details than, “doesn't work,” which tells us nothing useful. Remember we can't run your code. Did you find the collection controller code? Is the readCharacter() method instance or static? Why are you creating that input helper object as a local variable?
 
Sheriff
Posts: 17153
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
That does not look like code that should be in a controller, by the way. A controller is responsible for routing client requests and system responses. If the client submits a review, the controller simply routes whatever the client submitted to the appropriate domain class or service class that handles reviews. Then the controller will determine what the client should see next based on how the domain or service class responds.
 
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

Junilu Lacar wrote:That does not look like code that should be in a controller, by the way. A controller is responsible for routing client requests and system responses. If the client submits a review, the controller simply routes whatever the client submitted to the appropriate domain class or service class that handles reviews. Then the controller will determine what the client should see next based on how the domain or service class responds.


I'm sorry i am really new to programming and don't really understand what you mean. Can you give an example of a controller class code?
 
Junilu Lacar
Sheriff
Posts: 17153
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
Sorry if this sounds a bit harsh but if you’re that new, then you’re probably trying to take on more than you can handle with this exercise. You shouldn’t try to build a car if you don’t know the difference between a steering wheel and a flywheel.

If you want to know more about Controllers, search for articles on Model View Controller design pattern
 
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
i have written the following bit of code but i still get no output.. i use inputHelper because without it i get an error on the next line of code(char c=inputHelper.readCharacter). i need char c in order to check the text input and trigger the appropriate input for my variables. as i said this bit of code modifies no variables.
 
Master Rancher
Posts: 4891
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

i still get no output


Perhaps the value in c is not what you expected.  Add a print statement after line 2 that prints the value in c so you can see what value it holds.
 
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

Norm Radder wrote:

i still get no output


Perhaps the value in c is not what you expected.  Add a print statement after line 2 that prints the value in c so you can see what value it holds.


i've finally got it working however another problem occured.. As you can see i added a while loop so i can modify multiple variables. i can now modify one variable then choose another and modify that one as well. However now i've got a different problem that occurred with the while loop. When i press "Q" which is meant for quitting the program i get the goodbye message printed but it still loops and prints "A: Restaurant Name -B:Restaurant Review -C:Restaurant Location -D:Restaurant Rating -E:Reviewer Name is -Q:Quit "  all over which is not meant to do that. Can anyone help with this? Any help is much appreciated
 
Norm Radder
Master Rancher
Posts: 4891
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you copy the contents of the command prompt window and paste it here to show what you are talking about?


Also add a final else statement at the end of the chained if/else if statements that prints a message for when none of the above statements were true.  Be sure to include the value of c in the message.
 
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

Norm Radder wrote:Can you copy the contents of the command prompt window and paste it here to show what you are talking about?


Also add a final else statement at the end of the chained if/else if statements that prints a message for when none of the above statements were true.  Be sure to include the value of c in the message.


Restaurant Reviews App
=====================


A: Restaurant Name -B:Restaurant Review -C:Restaurant Location -D:Restaurant Rating -E:Reviewer Name is -Q:Quit :
A
Enter Restaurant Name: :
bodega
Restaurant Name is: bodega
A: Restaurant Name -B:Restaurant Review -C:Restaurant Location -D:Restaurant Rating -E:Reviewer Name is -Q:Quit :
b
Enter Restaurant Review: :
food was shabby
Restaurant Review is: food was shabby
A: Restaurant Name -B:Restaurant Review -C:Restaurant Location -D:Restaurant Rating -E:Reviewer Name is -Q:Quit :
c
Enter Restaurant Location: :
downtown
Restaurant Location is: downtown
A: Restaurant Name -B:Restaurant Review -C:Restaurant Location -D:Restaurant Rating -E:Reviewer Name is -Q:Quit :
d
Enter Restaurant Rating: :
2
Restaurant Rating is: 2
A: Restaurant Name -B:Restaurant Review -C:Restaurant Location -D:Restaurant Rating -E:Reviewer Name is -Q:Quit :
q
Thank you for using Restaurant Reviews App. Good bye.
Restaurant Id Order
===================

A. Add Restaurant B. Add Restaurant Review C. List Location Restaurant Data In Name Order D. List Restaurant Ratings Q. Quit
Enter choice:
 
Norm Radder
Master Rancher
Posts: 4891
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where is the } that matches the { on line 1?
Where is the } that matches the { on line 8?
What code follows line 40?

What code surrounds the posted code?  Can there to another loop that is not shown that includes/wraps the posted code?
 
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

Norm Radder wrote:Where is the } that matches the { on line 1?
Where is the } that matches the { on line 8?
What code follows line 40?

What code surrounds the posted code?  Can there to another loop that is not shown that includes/wraps the posted code?



my full code is as follows..
 
Norm Radder
Master Rancher
Posts: 4891
38
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code block inside the {}s on lines 22 and 66 is  a sort of addition to the constructor for the class.  It is executed when a new instance of the class is created.
Is there more than one instance of the RestaurantController class created?  
To see: add print statements just after line 22 and just before line 66 to show when that code was executed.
 
Did you ever grow anything in the garden of your mind? - Fred Rogers. Tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic