Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a class definition that describes a basketball player with appropriate in

ID: 3586471 • Letter: C

Question

Create a class definition that describes a basketball player with appropriate instance variables and get and set methods so that users can access the class later to create objects. Name this class Basketball.java.

Your program will require the user to enter 5 players with these fields: First Name, Last Name, Points Scored, Rebounds, and Fouls.

Create a second class named BasketballStatistics.java. It will contain these features:

This is assumed to be a “secure data entry system,” so you must require correct entry of a system username and password before data can be entered. The username MUST be “admin,” although the interface must allow for any case combination. The password MUST be “9999.” If there are a total of 3 incorrect login attempts, the user will be presented with a message that he/she has reached the maximum number of incorrect logins, and the program must terminate. Write your own custom method(s) to accomplish this.Hint: think loops!

Once the user is authenticated, you will need to present the user with a series of questions that prompt the user to enter First Name, Last Name, Points Scored, Rebounds, and Fouls for exactly 5 players, utilizing the class definition that we created earlier). Each player must be considered to be an object. Also, the input data must be of the correct format as specified below:

Text entries must be modified to this convention: All uppercase letters (example: User enters “jerEmY” but we store it as JEREMY in the object field).

There must be some sort of validation so that integer fields are “realistic.” For example, in basketball, points and rebounds are never a negative number, and are highly unlikely to be more than 99. Also, in college basketball, it is impossible to accumulate a negative number, or more than 5 fouls.

NOTE: You do not have to validate for empty strings or data type entry errors (such as entering strings for integer fields). We will cover this in the second half of the course.

Once all 5 players are initialized, print out a nice columnar output of each player, preceded by a header row that defines the data. Note below that first and last name fields have been concatenated, and that first name is modified so that the first initial, a period, and a max of 8 letters of the last name are shown! For example, if one player’s name is Billy Swarovsky, it would be displayed like this:

Hint: Because the Last Name field must print out as exactly 8 characters, I would recommend that you handle padding this field to exactly 8 (if the name is less than 8 characters) when you store the value in the object field, and truncating the field to exactly 8 when you print the report, if it is more than 8 characters.

At the bottom of the report, there should be team totals that add the fields for the team. Points will be deducted if columns do not line up.

Sample output could look like this:

Player Name                 Pts          Rbs          Fouls

N. JONES                        15           9              3

S. AUSTIN                       9              4              2

A. MAZZONE                 12           0              1

M. KING                         4              1              5

A. JOHNSTON                0              4              2

TEAM TOTALS               40           18           13

layer Name Pts Rbs Fouls SWAROUSK

Explanation / Answer

Basketball.java

public class Basketball {

//Declaring instance variables
private String firstname;
private String lastname;
private int pointsScored;
private int rebounds;
private int fouls;
//Parameterized constructor
public Basketball(String firstname, String lastname, int pointsScored,
int rebounds, int fouls) {
super();
this.firstname = firstname;
this.lastname = lastname;
this.pointsScored = pointsScored;
this.rebounds = rebounds;
this.fouls = fouls;
}

//getters and setters
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public int getPointsScored() {
return pointsScored;
}
public void setPointsScored(int pointsScored) {
this.pointsScored = pointsScored;
}
public int getRebounds() {
return rebounds;
}
public void setRebounds(int rebounds) {
this.rebounds = rebounds;
}
public int getFouls() {
return fouls;
}
public void setFouls(int fouls) {
this.fouls = fouls;
}

}

_________________

package org.students;

import java.util.Scanner;

public class BasketballStatistics {

/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {


//Declaring variables
String username = "admin", un;
int password = 9999, pwd;
int attempts = 0, maxattempts = 3, flag = 0;
String fname, lname;
int scored, rebounds, foul;

/* This while loop continues to execute
* until 3 times or if user enters valid username and pwd
*/
while (attempts < maxattempts) {
//Getting the username entered by the user
System.out.print("Enter the User Name :");
un = sc.next();
if (un.equalsIgnoreCase(username)) {
while (attempts < maxattempts) {
//Getting the password entered by the user
System.out.print("Enter the Password :");
pwd = sc.nextInt();
if (pwd != password) {
System.out.println("** Invalid Password **");
attempts++;
continue;
} else {
System.out.println("** Login Successful **");
flag = 1;
break;
}

}
} else {
System.out.println("** Invalid Username **");
attempts++;
continue;
}
break;
}

if (flag == 1) {
//Creating an array of 5 Basketball class object array
Basketball bb[] = new Basketball[5];

//Getting the each player details
for (int i = 0; i < bb.length; i++) {
System.out.println("Player#" + (i + 1) + ":");
System.out.print("Enter the Firstname :");
fname = sc.next();
System.out.print("Enter the Lastname :");
lname = sc.next();
System.out.print("Enter Points :");
scored = getValue();
System.out.print("Enter Rebounds :");
rebounds = getValue();
System.out.print("Enter Fouls :");
foul = getFoulsValue();

//populate each player details in the array by creating object
bb[i] = new Basketball(fname.toUpperCase(), lname.toUpperCase(), scored, rebounds, foul);
}

String ln = "";

//Displaying the statistics
System.out.println("Player Name Pts Rbs Fouls");
for (int i = 0; i < bb.length; i++) {


if (bb[i].getLastname().length() > 8) {
ln = bb[i].getLastname().substring(0, 8);
} else {
ln = bb[i].getLastname();
}
System.out.println(bb[i].getFirstname().charAt(0) + "." + ln + " " + bb[i].getPointsScored() + " " + bb[i].getRebounds() + " " + bb[i].getFouls());
}

System.out.print("Team Totals :");
int ptsTot = 0, rebooundsTot = 0, foulsTot = 0;

//Displaying the totals
for (int i = 0; i < bb.length; i++) {
ptsTot += bb[i].getPointsScored();
rebooundsTot += bb[i].getRebounds();
foulsTot += bb[i].getFouls();
}
System.out.print(ptsTot + " " + rebooundsTot + " " + foulsTot);
}


}

//This method will get valid fouls number
private static int getFoulsValue() {
int val;
while (true) {
val = sc.nextInt();

if (val < 0 || val > 5) {
System.out.println("Invalid.Must be between 0-5");
System.out.print("Enter :");
continue;
} {
break;
}
}
return val;
}

//This method will get valid score and rebounds value
private static int getValue() {
int val;
while (true) {
val = sc.nextInt();

if (val < 0 || val > 99) {
System.out.println("Invalid.Must be between 0-99");
System.out.print("Enter :");
continue;
} {
break;
}
}
return val;
}

}

_______________________

Output:

Enter the User Name :admnss

** Invalid Username **

Enter the User Name :admin

Enter the Password :8999

** Invalid Password **

Enter the Password :9999

** Login Successful **

Player#1:

Enter the Firstname :Nancy

Enter the Lastname :jones

Enter Points :15

Enter Rebounds :109

Invalid.Must be between 0-99

Enter :9

Enter Fouls :3

Player#2:

Enter the Firstname :Steve

Enter the Lastname :austin

Enter Points :9

Enter Rebounds :4

Enter Fouls :2

Player#3:

Enter the Firstname :Amzer

Enter the Lastname :mazzone

Enter Points :12

Enter Rebounds :0

Enter Fouls :1

Player#4:

Enter the Firstname :Miley

Enter the Lastname :king

Enter Points :4

Enter Rebounds :1

Enter Fouls :5

Player#5:

Enter the Firstname :Alice

Enter the Lastname :johnstoney

Enter Points :0

Enter Rebounds :4

Enter Fouls :2

Player Name Pts Rbs Fouls

N.JONES 15 9 3

S.AUSTIN 9 4 2

A.MAZZONE 12 0 1

M.KING 4 1 5

A.JOHNSTON 0 4 2

Team Totals : 40 18 13


_____________Could you rate me well.Plz .Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote