PlayerRoster.java:29: error: class PlayerRosterApp is public, should be declared in a file named PlayerRosterApp.java public class PlayerRosterApp                                               { ^ 1 error

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

PlayerRoster.java:29: error: class PlayerRosterApp is public, should be declared in a file named PlayerRosterApp.java public class PlayerRosterApp

                                              { ^ 1 error

import java.util.Scanner;

class Player {
    private int jerseyNumber;
    private int playerRating;

    public Player(int jerseyNumber, int playerRating) {
        this.jerseyNumber = jerseyNumber;
        this.playerRating = playerRating;
    }

    public int getJerseyNumber() {
        return jerseyNumber;
    }

    public void setJerseyNumber(int jerseyNumber) {
        this.jerseyNumber = jerseyNumber;
    }

    public int getPlayerRating() {
        return playerRating;
    }

    public void setPlayerRating(int playerRating) {
        this.playerRating = playerRating;
    }
}

public class PlayerRosterApp {
    public static void main(String[] args) {
        Scanner scnr = new Scanner(System.in);

        int rosterSize = 5;
        Player[] roster = new Player[rosterSize];

        // Prompt the user to input five pairs of numbers
        for (int i = 0; i < rosterSize; i++) {
            System.out.print("Enter player " + (i + 1) + "'s jersey number (0 - 99): ");
            int jerseyNumber = scnr.nextInt();
            System.out.print("Enter player " + (i + 1) + "'s rating (1 - 9): ");
            int playerRating = scnr.nextInt();

            roster[i] = new Player(jerseyNumber, playerRating);
        }

        char option;
        do {
            // Implement the menu of options
            System.out.println("\nMENU");
            System.out.println("a - Add a player");
            System.out.println("o - Output roster");
            System.out.println("u - Update player rating");
            System.out.println("a - Output players above a rating");
            System.out.println("r - Replace player");
            System.out.println("q - Quit");

            System.out.print("Choose an option: ");
            option = scnr.next().charAt(0);

            switch (option) {
                case 'o':
                    // Output roster
                    System.out.println("Roster:");
                    for (int i = 0; i < rosterSize; i++) {
                        Player player = roster[i];
                        System.out.println("Player " + (i + 1) + " -- Jersey Number: " + player.getJerseyNumber() + ", Rating: " + player.getPlayerRating());
                    }
                    break;
                case 'u':
                    // Update player rating
                    System.out.print("Enter a player's jersey number: ");
                    int updateJersey = scnr.nextInt();
                    System.out.print("Enter a new rating for player " + updateJersey + ": ");
                    int newRating = scnr.nextInt();

                    for (int i = 0; i < rosterSize; i++) {
                        if (roster[i].getJerseyNumber() == updateJersey) {
                            roster[i].setPlayerRating(newRating);
                            break;
                        }
                    }
                    break;
                case 'a':
                    // Output players above a rating
                    System.out.print("Enter a rating: ");
                    int ratingThreshold = scnr.nextInt();
                    System.out.println("Players with a rating above " + ratingThreshold + ":");
                    for (int i = 0; i < rosterSize; i++) {
                        if (roster[i].getPlayerRating() > ratingThreshold) {
                            System.out.println("Player " + (i + 1) + " -- Jersey Number: " + roster[i].getJerseyNumber() + ", Rating: " + roster[i].getPlayerRating());
                        }
                    }
                    break;
                case 'r':
                    // Replace player
                    System.out.print("Enter a player's jersey number to replace: ");
                    int replaceJersey = scnr.nextInt();
                    System.out.print("Enter a new jersey number: ");
                    int newJersey = scnr.nextInt();
                    System.out.print("Enter a new rating: ");
                    int newPlayerRating = scnr.nextInt();

                    for (int i = 0; i < rosterSize; i++) {
                        if (roster[i].getJerseyNumber() == replaceJersey) {
                            roster[i].setJerseyNumber(newJersey);
                            roster[i].setPlayerRating(newPlayerRating);
                            break;
                        }
                    }
                    break;
                case 'q':
                    // Quit the program
                    break;
                default:
                    System.out.println("Invalid option. Please choose a valid option from the menu.");
            }
        } while (option != 'q');
    }
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Linux
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education