-2

My code looks like this, I wanted to design my program, something like a card, it'll ask for a color then print out a message.

My problem is, I can't really close it up...

import java.util.Scanner;
public class Main{
    public static void main(String args[]) {
        Scanner cin = new Scanner(System.in);
        String color;
        
        System.out.println("------------------------------------------------------");
        System.out.println("|                  Welcome Card!!                    |");
        System.out.println("|                   Pick a color                     |");
        System.out.println("|                                                    |");
        System.out.println("|              Green, Blue, Red, Orange              |");
        System.out.println("|                                                    |");
        System.out.println("|                                                    |");
        System.out.print("|\t\t\t\t       "); color = cin.nextLine();
        
        switch (color.toLowerCase()){
            case "blue":
                System.out.println("|                    Success                         |");
                System.out.println("------------------------------------------------------");
                break;

            default:
                System.out.println("unsuccessful");
        }
        
        }
    }

the output looks like this:

------------------------------------------------------
|                  Welcome Card!!                    |
|                   Pick a color                     |
|                                                    |
|              Green, Blue, Red, Orange              |
|                                                    |
|                                                    |
|                      blue
|                    Success                         |
------------------------------------------------------

what I want to achieve:

------------------------------------------------------
|                  Welcome Card!!                    |
|                   Pick a color                     |
|                                                    |
|              Green, Blue, Red, Orange              |
|                                                    |
|                                                    |
|                     blue                           |
|                    Success                         |
------------------------------------------------------

It's still a rough draft, just tryna figure out how to put another vertical line on that gap...

Migu
  • 1
  • 1
  • It sounds like you actually want more of a curses-like interface. – Dave Newton Feb 24 '23 at 14:52
  • Check the content of the user input and remove anything you don't want in there. – Igor Flakiewicz Feb 24 '23 at 14:53
  • See [this thread](https://stackoverflow.com/questions/1066318/how-to-read-a-single-char-from-the-console-in-java-as-the-user-types-it). Short answer, there is no easy, completely portable method that works under all conditions. – Idle_Mind Feb 24 '23 at 19:01

1 Answers1

0

What you want to achieve is not possible using pure System.in/System.out console stream input/output. You would need a character base UI framework to implement something like that.

aled
  • 21,330
  • 3
  • 27
  • 34