java

help with implementing a menu
103 Replies
JavaBot
JavaBot6mo 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
zeusOP6mo 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
dan1st6mo ago
Which part of that is the issue? What UI framework are you using?
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
zeus
zeusOP6mo ago
Where can i learn methods I kinda missed the class U mean what i write to write the code?
JavaBot
JavaBot6mo 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
zeusOP6mo ago
Netbeans if thats wym
dan1st
dan1st6mo ago
Swing? JavaFX? Something else?
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
dan1st
dan1st6mo ago
I overread tthat part lol
dan1st
dan1st6mo ago
Dev.java: The Destination for Java Developers
Classes and Objects - Dev.java
Defining your own classes, declaring member variables, methods, and constructors.
zeus
zeusOP6mo 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
dan1st6mo ago
idk what you want to know
zeus
zeusOP6mo ago
ok so
zeus
zeusOP6mo ago
No description
zeus
zeusOP6mo ago
im stuck here what do i do for the other numbers
dan1st
dan1st6mo ago
What do you want to do? First you can use else-if
zeus
zeusOP6mo ago
if user inputs 2 sout etc
dan1st
dan1st6mo ago
use an else-if
zeus
zeusOP6mo ago
havent studied that could u help
dan1st
dan1st6mo 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
dan1st6mo 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
zeusOP6mo ago
how do i add the useres deposit to the initial balance
dan1st
dan1st6mo ago
What exactly should happen?
zeus
zeusOP6mo ago
so if the user wants to deposit x money to x balance
dan1st
dan1st6mo ago
What exactly should the program do? Should it ask the user for input? Should it change variables? Should it output something?
zeus
zeusOP6mo ago
so the user wants to deposit 500 to his account
dan1st
dan1st6mo ago
How does the program know?
zeus
zeusOP6mo ago
how do i update the balance to x + 500 x which is the balance before the deposit
dan1st
dan1st6mo ago
Yeah but how does the program know about it being 500?
zeus
zeusOP6mo ago
input from the user
dan1st
dan1st6mo ago
So it needs to ask the user for input
zeus
zeusOP6mo ago
ye
dan1st
dan1st6mo ago
ok so first you want to do something if the user enters 2, right?
zeus
zeusOP6mo ago
yes so i use else if
dan1st
dan1st6mo ago
yes
zeus
zeusOP6mo ago
No description
zeus
zeusOP6mo ago
Initial balance = initial balance + the amount of the deposit ?
dan1st
dan1st6mo 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
zeusOP6mo ago
none its net beans
dan1st
dan1st6mo ago
yes except that it needs to get the amount of the deposit from the user first, right?
zeus
zeusOP6mo ago
yeah
dan1st
dan1st6mo ago
Alt+Shift+F I think Do you know how to get it?
zeus
zeusOP6mo ago
No description
zeus
zeusOP6mo ago
No description
zeus
zeusOP6mo ago
@dan1st | Daniel whats wrong here
dan1st
dan1st6mo ago
you need to put the else if after the } of the if
zeus
zeusOP6mo ago
so i need another if?
dan1st
dan1st6mo 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
zeusOP6mo ago
No description
zeus
zeusOP6mo ago
@dan1st | Daniel
dan1st
dan1st6mo ago
same as before
zeus
zeusOP6mo ago
@dan1st | Daniel im done but i have one last problem
zeus
zeusOP6mo ago
how do i make the menu repeat the menu unless the user enters number 5
dan1st
dan1st6mo ago
You can use a loop
zeus
zeusOP6mo ago
howw and where
dan1st
dan1st6mo ago
around the whole thing you want to repeat
zeus
zeusOP6mo ago
so after the number 4? what do i write idk
dan1st
dan1st6mo ago
What do you want to repeat? Where should it continue if you don't exit?
zeus
zeusOP6mo 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
dan1st6mo ago
Should the printlns be repeated as well?
zeus
zeusOP6mo ago
and again until the user chooses option num 5
dan1st
dan1st6mo ago
ah ok then you probably want to include everything except the menu in the loop Do you know how loops work?
zeus
zeusOP6mo ago
so for (number>5; number++)?
dan1st
dan1st6mo ago
Do you want to count anything? I think you want a while or do-while loop
zeus
zeusOP6mo ago
so while (number>5 then what
dan1st
dan1st6mo ago
So you want to repeat it as long as the number is >5?
zeus
zeusOP6mo ago
yes if user enter 5 i want it to break btw
dan1st
dan1st6mo ago
Do you want to repeat as long as the number is >5?
zeus
zeusOP6mo ago
No description
zeus
zeusOP6mo ago
break didnt work so i used return
dan1st
dan1st6mo ago
Or until the number is >5?
zeus
zeusOP6mo ago
is that ok at 5 i want it to break so less than 5 ig
dan1st
dan1st6mo ago
I don't know whether your teachers are ok with you using return; like that
zeus
zeusOP6mo ago
its a presentation so i think he would give me extra marks for doing somth diff
dan1st
dan1st6mo ago
idk
zeus
zeusOP6mo ago
so how do i make it repeat itself
dan1st
dan1st6mo 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
zeusOP6mo ago
it repeats the account balance instead of the menu
dan1st
dan1st6mo ago
Is the part reading the number inside the loop?
zeus
zeusOP6mo ago
No description
dan1st
dan1st6mo 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
zeusOP6mo ago
will that fix the problem
dan1st
dan1st6mo ago
Note that you'd need to put that before the loop
zeus
zeusOP6mo ago
No description
dan1st
dan1st6mo ago
How do statements in Java end?
zeus
zeusOP6mo ago
No description
dan1st
dan1st6mo ago
you should use the correct names and that
zeus
zeusOP6mo ago
confused arent they correct
dan1st
dan1st6mo ago
Java is case sensitive
zeus
zeusOP6mo ago
nextint still doesnt work
dan1st
dan1st6mo ago
no nextInt
zeus
zeusOP6mo ago
lastly where do i put the while
dan1st
dan1st6mo ago
As I said, the loop should be around everything you want to repeat it's a block withh {} like if
zeus
zeusOP6mo ago
No description
dan1st
dan1st6mo ago
.
zeus
zeusOP6mo ago
which loop my brain hurts the if i tried still doesnt run ok now ir runs but it wont stop running
dan1st
dan1st6mo ago
the while loop if isn't a loop Can you show your code?
zeus
zeusOP6mo ago
is this good now
No description
dan1st
dan1st6mo ago
nice
JavaBot
JavaBot6mo 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.
Want results from more Discord servers?
Add your server