Question

Write a Java program that displays the following menu to the user (and allows the user to make a valid selection): 1- Tournam

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here's your full working code as asked in the question...

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
import java.io.File;
import java.util.*;
class test{
   static void option1(String arr[],int n){
       for(int i=0;i<n;i++){
           String inp = arr[i];
           int wins = 0;
           String res = "";
           for(int j=0;j<inp.length();j+=2){
               if(inp.charAt(j)=='W')
                   wins++;
               res += inp.charAt(j);
           }
           if(wins>=5){
               System.out.println("["+res+"]:Group 1\n");
           }else if(wins>=3){
               System.out.println("["+res+"]:Group 2\n");
           }else if(wins>=1){
               System.out.println("["+res+"]:Group 3\n");
           }else{
               System.out.println("Eliminated\n");
           }
       }
   }
   public static void main(String a[]){
       int option;
       Scanner sc = new Scanner(System.in);
       while(true){
           System.out.println("1-Tournament Selection\n");
           System.out.println("2-Magic Squares\n");
           System.out.println("3-Arrival Time\n");
           System.out.println("4-Quit\n");
           option = sc.nextInt();
           if(option==1){
               try{
               File file = new File("F:\\input.txt");
               sc = new Scanner(file);
               int n = Integer.parseInt(sc.nextLine());
               String arr[] = new String[n];
               int i = 0;
               while(sc.hasNextLine())
                   arr[i++] = sc.nextLine();
               option1(arr,n);
              
               break;
               }catch(Exception e){
               }
           }else if(option==2){
               break;
           }else if(option==3){
               break;
           }else if(option==4){
               break;
           }else{
               System.out.println("Please select a valid option\n");
               continue;
           }
       }
}
}

Add a comment
Know the answer?
Add Answer to:
Write a Java program that displays the following menu to the user (and allows the user to make a valid selection): 1- Tournament Selection 2- Magic Squares 3 -Arrival Time 4- Quit Once a valid select...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • // This program displays a menu and asks the user to make a 2 // selection....

    // This program displays a menu and asks the user to make a 2 // selection. An if/else if statement determines which item 3 // the user has chosen. 4 #include <iostream> 5 #include <iomanip> 6 using namespace std; 7 8 int main() 9 { 10 int choice; // To hold a menu choice 11 int months; // To hold the number of months 12 double charges; // To hold the monthly charges 13 14 // Constants for membership rates...

  • Write a Java program which allows the user to perform simple tasks on a calculator. A...

    Write a Java program which allows the user to perform simple tasks on a calculator. A series of methods allows the user to select an operation to perform and then enter operands. The first method displays a menu, giving the user the choice of typing in any one of the following: +, -, *, /, or % representing the usual arithmetic operators (Each operation should be done on numbers negative(-) to positive(+), positive(+) to negative(-), negative(-) to negative(-), and positive(+)...

  • IN JAVA. Write a program that lets the user play the game of Rock, Paper, Scissors...

    IN JAVA. Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. Don’t display the computer’s choice yet....

  • (Java) Write a program that lets the user play the game of Rock, Paper, Scissors against...

    (Java) Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. Don’t display the computer’s choice yet. The...

  • Write a C++ program that prompts the user with the following menu options: Erase-ArrayContent Count-Words Quit...

    Write a C++ program that prompts the user with the following menu options: Erase-ArrayContent Count-Words Quit 1. For Erase-ArrayContent option, write complete code for the C++ function Erase described below. The prototype for Erase function is as follow: void Erase( int a[ ], int * N, int * Search-Element) The function Erase should remove all occurrences of Search-Element from the array al). Note that array a[ ] is loaded with integer numbers entered by the user through the keyboard. N...

  • Java language: C Write a game program that allows the user to collect 4 tokens hidden...

    Java language: C Write a game program that allows the user to collect 4 tokens hidden in an array (cells) of size 10. The program asks the user to select a cell. Determine if there is a token in that cell or not, and give the user appropriate feedback. This program should keep letting user to select until the all tokens are collected. The program should display the total number of selections. Use rand_position Example input/output: There are four tokens....

  • C++ Implement Hot Potato game ________________________________________________ A group of people, numbered 1 to N, are sitting...

    C++ Implement Hot Potato game ________________________________________________ A group of people, numbered 1 to N, are sitting in a circle. Starting at person 1, a hot potato is passed. After X passes, the person holding the hot potato is eliminated, the circle closes ranks, and the game continues with the person who was sitting after the eliminated person picking up the hot potato. The last remaining person wins. For example: if X = 0 and N = 5, players are eliminated...

  • PLEASE INCLUDE SAW-PROMPTS FOR 2 PLAYERS NAMES(VALIDATE NAMES). SHOW MENU (PLAYER MUST SELECT FROM MENU B4...

    PLEASE INCLUDE SAW-PROMPTS FOR 2 PLAYERS NAMES(VALIDATE NAMES). SHOW MENU (PLAYER MUST SELECT FROM MENU B4 THE GAME STARTS 1=PLAY GAME, 2=SHOW GAME RULES, 3=SHOW PLAYER STATISTICS, AND 4=EXIT GAME WITH A GOODBYE MESSAGE.) PLAYERS NEED OPTION TO SHOW STATS(IN A DIFFERNT WINDOW-FOR OPTION 3)-GAME SHOULD BE rock, paper, scissor and SAW!! PLEASE USE A JAVA GRAPHICAL USER INTERFACE. MUST HAVE ROCK, PAPER, SCISSORS, AND SAW PLEASE This project requires students to create a design for a “Rock, Paper, Scissors,...

  • extra credit 1 Write a program that will display the following menu and prompt the user...

    extra credit 1 Write a program that will display the following menu and prompt the user for a selection: A) Add two numbers B) Subtract two numbers C) Multiply two numbers D) Divide two numbers X) Exit program The program should: display a hello message before presenting the menu accept both lower-case and upper-case selections for each of the menu choices display an error message if an invalid selection was entered (e.g. user enters E) prompt user for two numbers...

  • Java BasketBall Bar Chart Write a program that allows you to create a bar chart for...

    Java BasketBall Bar Chart Write a program that allows you to create a bar chart for the active members of a basketball team during a game. (Recall: there are only 5 active players on the court per team in a standard basketball game.) Your program should do the following tasks: 1) Prompt the user to store the first name of the five players 2) Prompt the user to enter the points scored by each player a. Use a do...while loop...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT