I am designing a bank system

Soon as the user opens the display the welcome message alone with all the latest offers are displayed without any input.

afterwards the user is given 4 set of instructions for example:
enter 1, 2, 3 or 4 to display the
1. Display balance
2. print statement
3. Top up
4. Bye

What I am struggling with is how to read the users input and display the instruction?

any help will be nice.

Recommended Answers

All 7 Replies

Is this a command line or GUI exercise?

Simple command line

1. Use Scanner class to read user input as a String.
2. Use parseInt(String) of Integer class to convert String to int.
3. Set up a logic to take next step dependent on user provided input

I haven't learn this in class :(

Can you make a sample for me so I can study it

import java.util.Scanner;

public class ScannerNew
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        String input;
        System.out.println("Welcome");
        System.out.println("Choose: a,b,c");
            input = sc.nextLine();
            if (input == "a")
                System.out.println("Letter is"+ input);  
               else
               {
                System.out.println("Error"); 
                }
            
    }

I am learning the Scanner

when I enter a into the display it doesn't output "Letter is a"

To compare strings you need to use equals method not logical operator "==".
So you will use

stringOne.equals(stringTwo)
//in your case
input.equals("a")

How to clear the the command line screen ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.