Related questions
Concept explainers
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');
}
}
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps
- Summary In this lab, you create a derived class from a base class, and then use the derived class in a Python program. The program should create two Motorcycle objects, and then set the Motorcycle’s speed, accelerate the Motorcycle object, and check its sidecar status. Instructions Open the file named Motorcycle.py. Create the Motorcycle class by deriving it from the Vehicle class. Call the parent class __init()__ method inside the Motorcycle class's __init()__ method. In theMotorcycle class, create an attribute named sidecar. Write a public set method to set the value for sidecar. Write a public get method to retrieve the value of sidecar. Write a public accelerate method. This method overrides the accelerate method inherited from the Vehicle class. Change the message in the accelerate method so the following is displayed when the Motorcycle tries to accelerate beyond its maximum speed: "This motorcycle cannot go that fast". Open the file named MyMotorcycleClassProgram.py. In the...arrow_forwardedit and finish class authenticate below do not give a solution (example copying from another source and giving it as a solution) that is not part of my code below. Also provided is user class. This is what I have so far please help me finish it. The task is listed below //Authenticate.java import java.util.Scanner;import java.io.File; Class Authenticate {private final int SIZE = 100;private User() users = new User[SIZE];public Authenticator (String fileName) throws Exception;Scanner sc = new Scanner(new File(fileName));int i = 0;While(sc.hasNext() && i < SIZE) {users[i] = Users.read(sc);i++}} public void authenticate(String username, String password) throws Exception{try {User u = null;for(User X : users) {if(x.getUsername().equals(username) && x.verifyPassword(password){ return ; _________________________________________________________________ //User.java import java.io.File;import java.io.FileNotFoundException;import java.util.Scanner; public class User{private...arrow_forwardpublic class VisitorPackage{// Declare data fields: an int named travelerID, // a String named destination, and // a double named totalCost.// Your code here... // Implement the default contructor.// Set the value of destination to N/A, and choose an // appropriate value for the other data fields,// Your code here... // Implement the overloaded constructor that passes new// values to all data fields.// Your code here... // Implement method getTotalCost to return the totalCost.// Your code here... // Implement method applyDiscount.//// This method applies a discount off of the total cost// of the tour. The way the discount is applied depends// on the kind of visitor.//// Child discount: the unit discount is subtracted ONCE// from the total cost of the tour.// Senior discount: the unit discount is subtracted TWICE// from the total cost of the tour.// Parameters:// - a char to indicate the kind of visitor// ('c' for child, 's' for senior)// - a double that indicates the amount of the...arrow_forward
- Written in Python It should have an init method that takes two values and uses them to initialize the data members. It should have a get_age method. Docstrings for modules, functions, classes, and methodsarrow_forward. Protected variables coth Task 1.1: Base Animai Create Animal Class with 3 protected attributes: • name - String • type-String • nocturnal - boolean • 4 public void Methods: • printInfo-should print: " is a(n) ." • printSleepInfo-should print: "s sleep during day." or "s sleep during night." • printRoam - should print: " walks around." • printFeed method - will implement in subclasses ●くろまる Subclass Owl: Constructor takes in name as argument and sets the attributes: • Type should be "Owl", nocturnal should be true and name is given as the argument ia printFeed method: • Should print "You give some mice." Overriding roam method: • Should print " flies around." Subclass Monkey: • Similar constructor: • Type should be "Monkey", nocturnal should be false and name is given as the argument printFeed method: Should print "You give some bananas." Create another public method called printClimb: Should print " climbs a tree!" Overriding roam method of owl as owls fly Animal printInfo():void...arrow_forwardProgram: File GamePurse.h: class GamePurse { // data int purseAmount; public: // public functions GamePurse(int); void Win(int); void Loose(int); int GetAmount(); }; File GamePurse.cpp: #include "GamePurse.h" // constructor initilaizes the purseAmount variable GamePurse::GamePurse(int amount){ purseAmount = amount; } // function definations // add a winning amount to the purseAmount void GamePurse:: Win(int amount){ purseAmount+= amount; } // deduct an amount from the purseAmount. void GamePurse:: Loose(int amount){ purseAmount-= amount; } // return the value of purseAmount. int GamePurse::GetAmount(){ return purseAmount; } File main.cpp: // include necessary header files #include <stdlib.h> #include "GamePurse.h" #include<iostream> #include<time.h> using namespace std; int main(){ // create the object of GamePurse class GamePurse dice(100); int amt=1; // seed the random generator srand(time(0)); // to play the...arrow_forward
- class SavingsAccount(object): RATE = 0.02 def __init__(self, name, pin, balance = 0.0): self._name = name self._pin = pin self._balance = balance def __str__(self): result = 'Name: ' + self._name + '\n' result += 'PIN: ' + self._pin + '\n' result += 'Balance: ' + str(self._balance) return result def __eq__(self,a): if self._name == a._name and self._pin == a._pin and self._balance == a._balance: return True else: return False def __gt__(self,a): if self._balance > a._balance: return True else: return False def getBalance(self): return self._balance def getName(self): return self._name def getPin(self): return self._pin def deposit(self, amount): self._balance += amount return self._balance...arrow_forwardPage < 32 of 41 You can override a private method defined in a subclass. (True/False)? ZOOM +arrow_forward1 using static System.Console; 2 class ShapesDemo 3 { static void Main() { abstract class GeometricFigure Create an application named ShapesDemo that 4 creates several objects 5 that descend from an abstract class called 7 { GeometricFigure . Each 8 public int Height { 10 11 9 GeometricFigure get includes a height , a { 12 13 width , and an area. return height; } 14 15 Provide get and set set { 16 17 accessors for each field height = value; except area ; the area } 18 is computed and is read- } only. Include an abstract 19 public int Width 20 { 21 22 method called get ComputeArea() that { computes the area of the 23 24 return width; GeometricFigure . 25 26 27 28 29 set Next you will create three { width = value; additional classes derived from the } 30 } 31 GeometricFigure class. Name these derived classes: Rectange , 32 public int Area 33 { 34 Square , and Triangle. get 35 { 36 37 return area; } 38 } 39 40 private void CalArea() 41 { 42 43 } 44 area = Height * Width; 45 } 46arrow_forward
- python: class Student:def __init__(self, first, last, gpa):self.first = first # first nameself.last = last # last nameself.gpa = gpa # grade point average def get_gpa(self):return self.gpa def get_last(self):return self.last class Course:def __init__(self):self.roster = [] # list of Student objects def add_student(self, student):self.roster.append(student) def course_size(self):return len(self.roster) # Type your code here if __name__ == "__main__":course = Course()course.add_student(Student('Henry', 'Nguyen', 3.5))course.add_student(Student('Brenda', 'Stern', 2.0))course.add_student(Student('Lynda', 'Robison', 3.2))course.add_student(Student('Sonya', 'King', 3.9)) student = course.find_student_highest_gpa()print('Top student:', student.first, student.last, '( GPA:', student.gpa,')')arrow_forwardPLZ help with the following: True/False In java it is possible to throw an exception, catch it, then re-throw that same exception if it is desired GUIs are windowing interfaces that handle user input and output. An interface can contain defined constants as well as method headings or instead of method headings. When a recursive call is encountered, computation is temporarily suspended; all of the information needed to continue the computation is saved and the recursive call is evaluated. Can you have a static method in a nonstatic inner class?arrow_forwardPython Code please Point of Sale Write a program that will manage the point of sale in a store. Build the ItemToPurchase class with the following: Attributes item_name (string) item_price (int) item_quantity (int) Default constructor Initializes item's name = "none", item's price = 0, item's quantity = 0 Method print_item_cost() Example of print_item_cost() output:Bottled Water 10 @ 1ドル = 10ドル Extend the ItemToPurchase class to contain a new attribute. item_description (string) - Set to "none" in default constructor Implement the following method for the ItemToPurchase class. print_item_description() - Prints item_description attribute for an ItemToPurchase object. Has an ItemToPurchase parameter. Example of print_item_description() output:Bottled Water: Deer Park, 12 oz. Build the ShoppingCart class with the following data attributes and related methods. Note: Some can be method stubs (empty methods) initially, to be completed in later steps. Parameterized constructor...arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education