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

How can i make a decimalFormatter in winPercentage? it should be the third decim

ID: 3562496 • Letter: H

Question

How can i make a decimalFormatter in winPercentage?

it should be the third decimal number in winPercentage output.(ex- .569 .543 .543 .321)

// Those are code i got far.

public class TeamClass {

private int wins;
private int loses;
private String teamName;
private String city;
private String division;
private double winPercentage;

public int getWins() {
return wins;
}
public void setWins(int wins) {
this.wins = wins;
}
public int getLoses() {
return loses;
}
public void setLoses(int loses) {
this.loses = loses;
}
public String getTeamName() {
return teamName;
}
public void setTeamName(String teamName) {
this.teamName = teamName;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getDivision() {
return division;
}
public void setDivision(String division) {
this.division = division;
}
public double getWinPercentage() {
return winPercentage;
}
public void setWinPercentage(double winPercentage) {
this.winPercentage = winPercentage;
}

public int compare(Object team) {
Double winPercentage=((TeamClass)team).getWinPercentage();
return winPercentage.compareTo(this.winPercentage);
}
}

---------------------------------------------------------

public class PlayOffSelectorClass {

public static void main(String[] args) {
ArrayList<TeamClass> list1;
list1 = new ArrayList<TeamClass>();


int confirm = 0;

while (confirm == 0) {
TeamClass teamClass = new TeamClass();
Scanner input = new Scanner(System.in);

System.out.println("Please enter the team name: ");
String tname = input.nextLine();
teamClass.setTeamName(tname);

System.out.println("Please enter city the team play in: ");
String city = input.nextLine();
teamClass.setCity(city);

System.out.println("Please enter the division the team play in: ");
String dsvn = input.nextLine();
teamClass.setDivision(dsvn);

System.out.println("Please enter the number of wins the team has: ");
int win = input.nextInt();
teamClass.setWins(win);

System.out.println("please enter the number of loses the team has: ");
int lose = input.nextInt();
teamClass.setLoses(lose);

double winPercentage = (double)
teamClass.getWins() / (teamClass.getWins() + teamClass.getLoses());
teamClass.setWinPercentage(winPercentage);

list1.add(teamClass);
System.out.println("continue = 0 or press any number if you want to stop");
confirm = input.nextInt();

}


System.out.println("East W L PTC");
for (int i = 0; i < list1.size(); i++) {
{

System.out.println(list1.get(i).getCity() + " " + list1.get(i).getTeamName() +
" " + list1.get(i).getWins() + " " + list1.get(i).getLoses() + " " +
list1.get(i).getWinPercentage());
}
}

}
}

Explanation / Answer

public class TeamClass {
private int wins;
private int loses;
private String teamName;
private String city;
private String division;
private double winPercentage;
public int getWins() {
return wins;
}
public void setWins(int wins) {
this.wins = wins;
}
public int getLoses() {
return loses;
}
public void setLoses(int loses) {
this.loses = loses;
}
public String getTeamName() {
return teamName;
}
public void setTeamName(String teamName) {
this.teamName = teamName;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getDivision() {
return division;
}
public void setDivision(String division) {
this.division = division;
}
public double getWinPercentage() {
return winPercentage;
}
public void setWinPercentage(double winPercentage) {
this.winPercentage = winPercentage;
}
public int compare(Object team) {
Double winPercentage=((TeamClass)team).getWinPercentage();
return winPercentage.compareTo(this.winPercentage);
}
}
---------------------------------------------------------
public class PlayOffSelectorClass {
public static void main(String[] args) {
ArrayList<TeamClass> list1;
list1 = new ArrayList<TeamClass>();
int confirm = 0;
while (confirm == 0) {
TeamClass teamClass = new TeamClass();
Scanner input = new Scanner(System.in);
System.out.println("Please enter the team name: ");
String tname = input.nextLine();
teamClass.setTeamName(tname);
System.out.println("Please enter city the team play in: ");
String city = input.nextLine();
teamClass.setCity(city);
System.out.println("Please enter the division the team play in: ");
String dsvn = input.nextLine();
teamClass.setDivision(dsvn);
System.out.println("Please enter the number of wins the team has: ");
int win = input.nextInt();
teamClass.setWins(win);
System.out.println("please enter the number of loses the team has: ");
int lose = input.nextInt();
teamClass.setLoses(lose);
double winPercentage = (double)
teamClass.getWins() / (teamClass.getWins() + teamClass.getLoses());
teamClass.setWinPercentage(winPercentage);
list1.add(teamClass);
System.out.println("continue = 0 or press any number if you want to stop");
confirm = input.nextInt();
}
System.out.println("East W L PTC");
String pattern = "###.###";
DecimalFormat decimalFormat = new DecimalFormat(pattern);

for (int i = 0; i < list1.size(); i++) {
{
System.out.println(list1.get(i).getCity() + " " + list1.get(i).getTeamName() +
" " + list1.get(i).getWins() + " " + list1.get(i).getLoses() + " " +
decimalFormat.format(list1.get(i).getWinPercentage()));
}
}
}
}

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