Answered You can hire a professional tutor to get the answer.

QUESTION

1 program that reads a person's first and last names, separated by a space. Then the program outputs last name, comma, first name. End with newline....

2.11.1

Jones, Maya

import java.util.Scanner;

public class SpaceReplace {

  public static void main (String [] args) {

   Scanner scnr = new Scanner(System.in);

   String firstName;

   String lastName;

   /* Your solution goes here */

  }

}

3.7.1: Detect specific values.

make an expression that prints "Special number" if specialNum is -99, 0, or 44. 

import java.util.Scanner;

public class FindSpecialValue {

  public static void main (String [] args) {

   Scanner scnr = new Scanner(System.in);

   int specialNum;

   specialNum = scnr.nextInt();

   if (/* Your solution goes here */) {

     System.out.println("Special number");

   }

   else {

     System.out.println("Not special number");

   }

  }

}

5.4.1: Method with branch: Popcorn.

Complete method printPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than 2, print "Too small". If greater than 10, print "Too large". Otherwise, compute and print 6 * bagOunces followed by " seconds". End with a newline. Example output for ounces = 7:

42 seconds

import java.util.Scanner;

public class PopcornTimer {

  public static void printPopcornTime(int bagOunces) {

   /* Your solution goes here */

  }

  public static void main (String [] args) {

   Scanner scnr = new Scanner(System.in);

   int userOunces;

   userOunces = scnr.nextInt();

   printPopcornTime(userOunces);

  }

}

6.2.3: Printing array elements with a for loop.

Write for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards, then backwards. End each loop with a newline. Ex: If courseGrades = {7, 9, 11, 10}, print:

7 9 11 10 10 11 9 7 }

}

6.15 Ch 5 Program: Soccer team roster (Java)

This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balanced team.

(1) Prompt the user to input five pairs of numbers: A player's jersey number (0 - 99) and the player's rating (1 - 9). Store the jersey numbers in one int array and the ratings in another int array. Output these arrays (i.e., output the roster). (3 pts) 

Ex:

player 's jersey number:84Enter player 1's rating:Enter player 's jersey number:23Enter player 2's rating:Enter player 's jersey number:4Enter player 3's rating:Enter player 's jersey number:30Enter player 4's rating:Enter player 's jersey number:66Enter player 5's rating:ROSTERPlayer -- Jersey number: , Rating: Player -- Jersey number: , Rating: ...

(2) Implement a menu of options for a user to modify the roster. Each option is represented by a single character. The program initially outputs the menu, and outputs the menu after a user chooses an option. The program ends when the user chooses the option to Quit. For this step, the other options do nothing. (2 pt) 

Ex:

MENUu - player ratinga - players above a ratingr - playero - rosterq - Quit an :

(3) Implement the "Output roster" menu option. (1 pt) 

Ex:

ROSTERPlayer 1 Player 2 ...

(4) Implement the "Update player rating" menu option. Prompt the user for a player's jersey number. Prompt again for a new rating for the player, and then change that player's rating. (1 pt) 

Ex:

Enter a jersey number:Enter a rating player:...

(5) Implement the "Output players above a rating" menu option. Prompt the user for a rating. Print the jersey number and rating for all players with ratings above the entered value. (2 pts) 

Ex:

a rating:ABOVE Player -- Jersey number: , Rating: ...

(6) Implement the "Replace player" menu option. Prompt the user for the jersey number of the player to replace. If the player is in the roster, then prompt again for a new jersey number and rating. Update the replaced player's jersey number and rating. (2 pts) 

Ex:

Enter a jersey number:Enter a jersey number:Enter a rating the player:

import java.util.Scanner;

public class PlayerRoster {

  public static void main(String[] args) {

    Scanner scanner = null;

    try {

      scanner = new Scanner(System.in);

      int[] playerJerseyNumber = new int[5];

      int[] playerRating = new int[5];

      for (int i = 0; i < 5; i++) {

        //Taking jersey number till it is in the range of 0-99

        while(true){

          System.out.println("Enter player " + (i + 1)

              + "'s jersey number:");

          playerJerseyNumber[i] = scanner.nextInt();

          if(0 <= playerJerseyNumber[i] && playerJerseyNumber[i] <= 99 ){

           break;

          }else{

            System.out.println("Jersey number must be 0-99");

          }

        }

        //Taking playerRating till it is in the range of 1-9

        while(true){

          System.out.println("Enter player " + (i + 1) + "'s rating:");

          playerRating[i] = scanner.nextInt();

          if(1 <= playerRating[i] && playerRating[i] <= 9 ){

            break;

          }else{

            System.out.println("Player's ratings must be 1-9");

          }

        }

        System.out.println("");

      }

      System.out.println("ROSTER");

      //Displaying the rosters

      for (int i = 0; i < 5; i++) {

        System.out.println("Player " + (i + 1) + " -- Jersey number: "

            + playerJerseyNumber[i] + ", Rating: "

            + playerRating[i]);

      }

      System.out.println("");

      //Printing the menu

      do {

        System.out.println("MENU" + "nu - Update player rating"

            + "na - Output players above a rating"

            + "nr - Replace player" + "no - Output roster"

            + "nq - Quit");

        System.out.println("");

        System.out.println("Choose an option:");

        char choice = scanner.next().charAt(0);

        switch (choice) {

          case 'u': {

            System.out.println("Enter a jersey number:");

            int playerJersey = scanner.nextInt();

            System.out.println("Enter a new rating for player:");

            int newRating = scanner.nextInt();

            for (int i = 0; i < 5; i++) {

              if (playerJerseyNumber[i] == playerJersey) {

                playerRating[i] = newRating;

                break;

              }

            }

          }

          break;

          case 'a': {

            System.out.println("Enter a rating:");

            int aboveRating = scanner.nextInt();

            for (int i = 0; i < 5; i++) {

              if (playerRating[i] > aboveRating) {

                System.out.println("Player " + (i + 1)

                    + " -- Jersey number: "

                    + playerJerseyNumber[i] + ", Rating: "

                    + playerRating[i]);

              }

            }

          }

          break;

          case 'r': {

            boolean flag = true;

            do {

              System.out.println("Enter a jersey number:");

              int newRating,playerNewJersey;

              int playerJersey = scanner.nextInt();

              for (int i = 0; i < 5; i++) {

                if ((playerJerseyNumber[i] == playerJersey)) {

                  //Taking jersey number till it is in the range of 0-99

                  while(true){

                    System.out.println("Enter a new jersey number:");

                    playerNewJersey = scanner.nextInt();

                    if(0 <= playerNewJersey && playerNewJersey <= 99 ){

                      break;

                    }else{

                      System.out.println("Jersey number must be 0-99");

                    }

                  }

                  //Taking playerRating till it is in the range of 1-9

                  while(true){

                    System.out.println("Enter a new rating for player:");

                    newRating = scanner.nextInt();

                    if(1 <= newRating && newRating <= 9 ){

                      break;

                    }else{

                      System.out.println("Player's ratings must be 1-9");

                    }

                  }

                  playerJerseyNumber[i] = playerNewJersey;

                  playerJerseyNumber[i] = playerJersey;

                  playerRating[i] = newRating;

                  flag = false;

                  break;

                }

              }

              if (!flag) {

                System.out.println("Error: Invalid Jersey Number...n Try Again...");

              }

            } while (flag);

          }

          break;

          case 'o': {

            System.out.println("ROSTER");

            for (int i = 0; i < 5; i++) {

              System.out.println("Player " + (i + 1)

                  + " -- Jersey number: " + playerJerseyNumber[i]

                  + ", Rating: " + playerRating[i]);

            }

          }

          break;

          case 'q':

            break;

          default:

            break;

        }

        if (choice == 'q')

          break;

      } while (true);

    } catch (Exception e) {

    }

    return;

  }

}

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question