java

help with implementing a menu
103 Replies
JavaBot
JavaBot7mo ago
This post has been reserved for your question.
Hey @zeus! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
zeus
zeusOP7mo ago
Implement a menu system to allow the user to perform the following operations: • View Account: Display the user's name and balance. • Deposit Money: Prompt the user to enter an amount to deposit. Update the balance accordingly. • Withdraw Money: Prompt the user to enter an amount to withdraw. Ensure that there are sufficient funds before performing the withdrawal. • Check Balance: Display the current balance i do not know how its part of my hw
dan1st
dan1st7mo ago
Which part of that is the issue? What UI framework are you using?
Unknown User
Unknown User7mo ago
Message Not Public
Sign In & Join Server To View
zeus
zeusOP7mo ago
Where can i learn methods I kinda missed the class U mean what i write to write the code?
JavaBot
JavaBot7mo ago
If you are looking for a Java course, consider https://java-programming.mooc.fi/ which is a free course on Java Programming from the University of Helsinki. When doing the course, it is recommended to use Eclipse or IntelliJ instead of NetBeans.
zeus
zeusOP7mo ago
Netbeans if thats wym
dan1st
dan1st7mo ago
Swing? JavaFX? Something else?
Unknown User
Unknown User7mo ago
Message Not Public
Sign In & Join Server To View
dan1st
dan1st7mo ago
I overread tthat part lol
dan1st
dan1st7mo ago
Dev.java: The Destination for Java Developers
Classes and Objects - Dev.java
Defining your own classes, declaring member variables, methods, and constructors.
zeus
zeusOP7mo ago
confusion its my first year so yeah wasnt useful couldnt find what my teacher asked for he gave a example of how the program should be may i send it output what does he mean by implement a menu system im so confused and i only have 2 hours left
dan1st
dan1st7mo ago
idk what you want to know
zeus
zeusOP7mo ago
ok so
zeus
zeusOP7mo ago
No description
zeus
zeusOP7mo ago
im stuck here what do i do for the other numbers
dan1st
dan1st7mo ago
What do you want to do? First you can use else-if
zeus
zeusOP7mo ago
if user inputs 2 sout etc
dan1st
dan1st7mo ago
use an else-if
zeus
zeusOP7mo ago
havent studied that could u help
dan1st
dan1st7mo ago
Dev.java: The Destination for Java Developers
Control Flow Statements - Dev.java
This section describes the decision-making statements, the looping statements, and the branching statements supported by the Java programming language.
dan1st
dan1st7mo ago
I think that site can explain it better than me but essentially it means: - if number is 1, do XYZ (you already have that) - if not and the number is 2, do something else - if none of the previous conditions are true and the number is 3, do ... - etc
zeus
zeusOP7mo ago
how do i add the useres deposit to the initial balance
dan1st
dan1st7mo ago
What exactly should happen?
zeus
zeusOP7mo ago
so if the user wants to deposit x money to x balance
dan1st
dan1st7mo ago
What exactly should the program do? Should it ask the user for input? Should it change variables? Should it output something?
zeus
zeusOP7mo ago
so the user wants to deposit 500 to his account
dan1st
dan1st7mo ago
How does the program know?
zeus
zeusOP7mo ago
how do i update the balance to x + 500 x which is the balance before the deposit
dan1st
dan1st7mo ago
Yeah but how does the program know about it being 500?
zeus
zeusOP7mo ago
input from the user
dan1st
dan1st7mo ago
So it needs to ask the user for input
zeus
zeusOP7mo ago
ye
dan1st
dan1st7mo ago
ok so first you want to do something if the user enters 2, right?
zeus
zeusOP7mo ago
yes so i use else if
dan1st
dan1st7mo ago
yes
zeus
zeusOP7mo ago
No description
zeus
zeusOP7mo ago
Initial balance = initial balance + the amount of the deposit ?
dan1st
dan1st7mo ago
looks good so far Are you using Eclipse or IntelliJ? If this is Eclipse, press Ctrl+Shift+F. If it's IntelliJ, press Ctrl+Alt+L. This should reformat your code.
zeus
zeusOP7mo ago
none its net beans
dan1st
dan1st7mo ago
yes except that it needs to get the amount of the deposit from the user first, right?
zeus
zeusOP7mo ago
yeah
dan1st
dan1st7mo ago
Alt+Shift+F I think Do you know how to get it?
zeus
zeusOP7mo ago
No description
zeus
zeusOP7mo ago
No description
zeus
zeusOP7mo ago
@dan1st | Daniel whats wrong here
dan1st
dan1st7mo ago
you need to put the else if after the } of the if
zeus
zeusOP7mo ago
so i need another if?
dan1st
dan1st7mo ago
no for the corresponding else if
if(number == 1){
//...
}else if(number == 2){
//...
}else if(number == 3){//after the }
//...
}//...
if(number == 1){
//...
}else if(number == 2){
//...
}else if(number == 3){//after the }
//...
}//...
see this
zeus
zeusOP7mo ago
No description
zeus
zeusOP7mo ago
@dan1st | Daniel
dan1st
dan1st7mo ago
same as before
zeus
zeusOP7mo ago
@dan1st | Daniel im done but i have one last problem
zeus
zeusOP7mo ago
how do i make the menu repeat the menu unless the user enters number 5
dan1st
dan1st7mo ago
You can use a loop
zeus
zeusOP7mo ago
howw and where
dan1st
dan1st7mo ago
around the whole thing you want to repeat
zeus
zeusOP7mo ago
so after the number 4? what do i write idk
dan1st
dan1st7mo ago
What do you want to repeat? Where should it continue if you don't exit?
zeus
zeusOP7mo ago
ok so after user chooses 1 it gives name and balance and ends i dont want it to end i want it to display the menu again
dan1st
dan1st7mo ago
Should the printlns be repeated as well?
zeus
zeusOP7mo ago
and again until the user chooses option num 5
dan1st
dan1st7mo ago
ah ok then you probably want to include everything except the menu in the loop Do you know how loops work?
zeus
zeusOP7mo ago
so for (number>5; number++)?
dan1st
dan1st7mo ago
Do you want to count anything? I think you want a while or do-while loop
zeus
zeusOP7mo ago
so while (number>5 then what
dan1st
dan1st7mo ago
So you want to repeat it as long as the number is >5?
zeus
zeusOP7mo ago
yes if user enter 5 i want it to break btw
dan1st
dan1st7mo ago
Do you want to repeat as long as the number is >5?
zeus
zeusOP7mo ago
No description
zeus
zeusOP7mo ago
break didnt work so i used return
dan1st
dan1st7mo ago
Or until the number is >5?
zeus
zeusOP7mo ago
is that ok at 5 i want it to break so less than 5 ig
dan1st
dan1st7mo ago
I don't know whether your teachers are ok with you using return; like that
zeus
zeusOP7mo ago
its a presentation so i think he would give me extra marks for doing somth diff
dan1st
dan1st7mo ago
idk
zeus
zeusOP7mo ago
so how do i make it repeat itself
dan1st
dan1st7mo ago
you make the loop depend on number
//code before what you want to repeat
while(number != 5){
//all the code you want to repeat here
}
//code before what you want to repeat
while(number != 5){
//all the code you want to repeat here
}
Note that I used != here meaning it repeats as long as it isn't 5 you can also use something else
zeus
zeusOP7mo ago
it repeats the account balance instead of the menu
dan1st
dan1st7mo ago
Is the part reading the number inside the loop?
zeus
zeusOP7mo ago
No description
dan1st
dan1st7mo ago
You can split the int number = sc.nextInt(); into two statements int number = 0; creates the number variable and number = sc.nextInt(); sets it to a variable from the input Also don't forget about the curley braces
zeus
zeusOP7mo ago
will that fix the problem
dan1st
dan1st7mo ago
Note that you'd need to put that before the loop
zeus
zeusOP7mo ago
No description
dan1st
dan1st7mo ago
How do statements in Java end?
zeus
zeusOP7mo ago
No description
dan1st
dan1st7mo ago
you should use the correct names and that
zeus
zeusOP7mo ago
confused arent they correct
dan1st
dan1st7mo ago
Java is case sensitive
zeus
zeusOP7mo ago
nextint still doesnt work
dan1st
dan1st7mo ago
no nextInt
zeus
zeusOP7mo ago
lastly where do i put the while
dan1st
dan1st7mo ago
As I said, the loop should be around everything you want to repeat it's a block withh {} like if
zeus
zeusOP7mo ago
No description
dan1st
dan1st7mo ago
.
zeus
zeusOP7mo ago
which loop my brain hurts the if i tried still doesnt run ok now ir runs but it wont stop running
dan1st
dan1st7mo ago
the while loop if isn't a loop Can you show your code?
zeus
zeusOP7mo ago
is this good now
No description
dan1st
dan1st7mo ago
nice
JavaBot
JavaBot7mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?