Win a copy of liveProject: Protecting User Data with Spring Security and OAuth2 this week in the Spring forum!

Bishara Babish

Greenhorn
+ Follow
since Apr 26, 2021
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
2
Given in last 30 days
2
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Bishara Babish

Paul Clapham wrote:

Bishara Babish wrote:Bro that’s what I’m trying to fix all this time 😭😭
I don’t the user to type anything or any number to let the main work,I just need the main menu to show up.



If that's a problem, then you really ought to put that code aside and work on some simpler code which just gets the menu and the related user input working. All that business about nodes is just distracting, you can put it back in to the working main-menu code when that's ready to go.


I already fixed it by myself,thanks anyways,idk how to close this topic.
1 week ago

Norm Radder wrote:

yes something has to be typed.
I mentioned before it’s for the Nodes.


Is your problem solved now since you know that something has to be typed?

Why can't the value be hardcoded in the constructor?  Why does the user have to enter a number?


Bro that’s what I’m trying to fix all this time 😭😭
I don’t the user to type anything or any number to let the main work,I just need the main menu to show up.
1 week ago

Piet Souris wrote:@OP,

you do not have to type a 1, before going on to the main menu. Any number will do. See line 3:

Your code is waiting here for the user to type in some number, However, there is no indication that a user has to type in anything, so the code seems to be stuck here.
It has been asked repeatedly: what good line 3 is for? Anyway, give a prompt here, so that it is clear that something has to be typed.

Another question: why is 'head' a static variable?


I listened to me IDE and changed it to static since all my things are static,and yes something has to be typed.
I mentioned before it’s for the Nodes.
1 week ago

Norm Radder wrote:Ok, that is a start.  But you left off the description of what was wrong with the way the program executed.
Now can you copy and paste it here as text (not an image)   Add comments to it  where the output is not what was desired or expected.




there.
1 week ago

Norm Radder wrote:You missed this part of my post again:


Can you copy the contents of the command prompt window and paste it here so we can see what happens when the code is executed?
Add some comments to the output line(s) where the operation of the program is not what was expected.


That will help us see what the problem is.


i dont follow,im sorry about this,see this pic if im right or not or give me an example sorry again for wasting your time on me.
1 week ago

Norm Radder wrote:You missed this part of my post:


Can you copy the contents of the command prompt window and paste it here so we can see what happens when the code is executed?
Add some comments to the output line(s) where the operation of the program is not what was expected.


That will help us see what the problem is.

,line 3 is “static Node head = new head(r)


You must have a different version of the code.  What I see at line 3:



Oh my bad sir,that’s the only scanner that has been declared for every method.
1 week ago

Norm Radder wrote:Yes, but what happens when line 3 is executed?  What does the user have to do?

Can you copy the contents of the command prompt window and paste it here so we can see what happens when the code is executed?
Add some comments to the output line(s) where the operation of the program is not what was expected.



I don’t actually get it, the scanner is just for all methods and stuff,line 3 is “static Node head = new head(r) which takes the scanner. It’s for the head,if you are intending to delete the line the heads in every method won’t work because it depends on it.
1 week ago

Norm Radder wrote:What happens when line 3 is executed?  What does the user do?


its for     static Node head = new Node(r);
1 week ago

Carey Brown wrote:Re-post your modified code.


do you mean a new topic?
1 week ago

Bishara Babish wrote:

Norm Radder wrote:

that didnt work too.


Can you post the new code?
A problem with Scanner class's methods is mixing use of the next...  methods with the nextLine method.
This discusses the problem: https://www.geeksforgeeks.org/why-is-scanner-skipping-nextline-after-use-of-other-next-functions/



i used InputForNode at the top of my code for every scanner. it wont fit in if i post the new code :c


import java.util.Scanner;


1 week ago

Carey Brown wrote:What are you trying to do with lines 5 & 6? Line 5 gets keyboard input but you are not prompting for any input. Line 6 creates a new Node that appears for the only purpose of having some thing for head to point to. Your code should be able to deal with an empty list without having to create a dummy node.

As Norm states only ONE Scanner for System.in for your **ENTIRE** program, however many classes that is. In general, pick your primary class to put it in or make a class specifically for that purpose. Example:
Also, never ever call KEYBOARD.close(). That will permanently close the input stream and it can't be re-opened until the program is re-run.



that is what i did as norm stated,i made one scanner for all methods.
1 week ago

Norm Radder wrote:

that didnt work too.


Can you post the new code?
A problem with Scanner class's methods is mixing use of the next...  methods with the nextLine method.
This discusses the problem: https://www.geeksforgeeks.org/why-is-scanner-skipping-nextline-after-use-of-other-next-functions/



i used InputForNode at the top of my code for every scanner. it wont fit in if i post the new code :c
1 week ago

Norm Radder wrote:I'd start by removing all but one Scanner object that reads from System.in.  There should only be one Scanner for System.in


i did tht as one scanner for every code but that didnt work too.
1 week ago
ive deleted some codes so it would fit,i checked every scanner..

1 week ago
hello there,ive written this code for my project and the write file is bugging me out.
whenever it writes in the "votes.txt" it writes flawlessly but whenever i add other voter it writes at the aame line and modifies it.
i dont now if that made sense but hope you help <3
1 week ago