🔒 Closed Pa help Po pano to icode

Status
Not open for further replies.

Hatdog-

Eternal Poster
Yung sa members Po kahit ilan nalang Kasi Wala naman akong ka group java language po pala to
Screenshot_2021-12-04-14-01-53-87_e46acc4301d552178f1fc7f923d8665c.jpg


Magbibigay nalang Po Ako Ng 100gcash sa makakatulong Yan lang Po Kasi Pera ko e
 
Console lang po ito ts?
Java:
import java.util.Scanner;
public class Main {
    static Scanner sc = new Scanner(System.in);
    static String showMenu(){
        System.out.println("[1] Hotdog-");
        System.out.println("[2] Exit the System");
        System.out.print("Enter your choice: ");
        String choice = sc.next();
        return choice;
    }
    static void process(int choice){
        switch(choice){
            case 1:
                choiceOne();
                break;
            case 2:
                System.exit(0);
        }
    }
    
    static void choiceOne(){
        //show all the Activities
        System.out.println("Showing All the Activities...");
        System.out.println("Activity 1");
        System.out.println("Activity 2");
        System.out.println("Activity 3");
        System.out.println("Activity 4");
        System.out.println("Activity 5");
        System.out.println("Activity 6");
    }
    
    static boolean isNumber(String choice){
        
        for(int i = 0; i < choice.length(); i++){
            if(!Character.isDigit(choice.charAt(i)))
                return false;
        }
        return true;
        
    }
    
    static boolean isValidChoice(String choice){
        if(choice.length() > 1 || choice.length() < 1)
            return false;
        else{
            if(choice.equals("Y") || choice.equals("y") || choice.equals("N") || choice.equals("n"))
                return true;
            else   
                return false;
        }
    }
    public static void main(String[] args) {
        Scanner sc2 = new Scanner(System.in);
        String cont = "";
        do{
            String choice = showMenu();
            cont = "";
            while(!isNumber(choice)){
                 System.out.println("Please input a valid choice.");
                 choice = showMenu();
            }
            process(Integer.parseInt(choice));
            while(!isValidChoice(cont)){
                System.out.println("Do you want to continue?[Y/N]: ");
                cont = sc2.next();
                if(!isValidChoice(cont)){
                    System.out.println("Please input a valid choice.");
                }
            }
        }while(cont.equals("Y") || cont.equals("y"));
            System.out.print("The Program Finished");
    }
}


Sample Output:
1638665244886.webp
 
Status
Not open for further replies.

About this Thread

  • 5
    Replies
  • 397
    Views
  • 4
    Participants
Last reply from:
Arcturus

Online now

Members online
886
Guests online
701
Total visitors
1,587

Forum statistics

Threads
2,276,945
Posts
28,973,238
Members
1,229,655
Latest member
Zfkirke0109
Back
Top