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

Could somebody help me with this program? The code I have is this: public class

ID: 3793074 • Letter: C

Question

Could somebody help me with this program? The code I have is this:

public class Bowler
{
String bowlerNumber;
int score1,score2,score3;

//gets the bowler number
public String getBowlerNumber()
{
return bowlerNumber;
}

//sets the bowler number
public void setBowlerNumber(String bowlerNumber)
{
this.bowlerNumber = bowlerNumber;
}

//gets the first score
public int getScore1()
{
return score1;
}

//sets the first score
public void setScore1(int score1)
{
this.score1 = score1;
}

//gets the second score
public int getScore2()
{
return score2;
}

//sets the second score
public void setScore2(int score2)
{
this.score2 = score2;
}

//gets the third score
public int getScore3()
{
return score3;
}

//sets the third score
public void setScore3(int score3)
{
this.score3 = score3;
}
  
}

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Scanner;
public class BowlerReports {
  
//creates an array list called Bowler
static HashMap> map;

public static void main(String args[])
{
ArrayList scores;


map = new HashMap>();
try{
  
//creates a scanner
Scanner s = new Scanner(System.in);

//opens the file Scores.txt
FileReader fr = new FileReader("Scores.txt");

//Reads the file
BufferedReader br= new BufferedReader(fr);
String line;

//creates a string buffer
StringBuffer sb = new StringBuffer();

//stores all of the info from the file into line
while((line=br.readLine())!=null)
{
sb.append(line);
}

//Converting into string and splitting using comma
String data[] = sb.toString().split("," + " ");
int i = 0;
Bowler b;
  
while(data.length > i)
{
//stores the Bowler array list in scores
scores = new ArrayList();
b = new Bowler();
b.setBowlerNumber(data[i]);

//takes all of the bowlers that have a number in the 100s
b.setScore1(Integer.parseInt(data[i+1]));

//takes all of the bowlers that have a number in the 200s
b.setScore2(Integer.parseInt(data[i+2]));

//takes all of the bowlers that have a number in the 300s
b.setScore3(Integer.parseInt(data[i+3]));

//takes all of the bowler that have a number in the 400s
i=i+4;

scores.add(b);

//adds the number to the list according to the number it starts with
if(map.containsKey(b.getBowlerNumber().charAt(0))){
ArrayList sl = map.get(b.getBowlerNumber().charAt(0));
sl.add(b);
map.put(b.getBowlerNumber().charAt(0), sl);
}

else
{
//adds the number normally
map.put(b.getBowlerNumber().charAt(0),scores);
}
}

BowlerReports bReport = new BowlerReports();

int j = 0;
while(j == 0)
{
//asks the user to select what report they would like
System.out.println("Please select what report you would like");

System.out.println("1. A report with all of the bowlers and their scores");

System.out.println("2. A report with all of the bowlers scores and their averages");

System.out.println("3. A repot with all of the bowlers and their team totals");

System.out.println("4. To exit the program");

//creates a scanner to record the users input
Scanner sc = new Scanner(System.in);

//stores the users input
int choice = sc.nextInt();

//chooses what to do with the users input
switch(choice)
{
//shows the Bowlers numbers and scores
case 1: bReport.generateReport(map);
break;
  
//shows the Bowlers scores and average scores
case 2: bReport.generateReportAvg(map);
break;
  
//shows the Bowlers scores and their team scores
case 3: bReport.generateReportGT(map);
break;

// exits the program
case 4: j = 1;
System.out.println("See ya later!");
break;
  
//if the user enters an invalid entry then it propmts them to enter in the correct entry
default: System.out.println("A number between 1 and 4");
}   
}
}
catch(Exception e)
{
e.printStackTrace();
}
  
}

private void generateReport(Character teamName)
{
ArrayList als = map.get(teamName);
Iterator bow = als.iterator();

while(bow.hasNext())
{
Bowler bb = bow.next();
  
//shows the bowler number and their three scores
System.out.println("Bowler " + bb.getBowlerNumber() + " scores are: " +" "+bb.getScore1()+", "+bb.getScore2()+", "+bb.getScore3());

System.out.println();
}
}

private void generateReportAvg(Character average)
{
ArrayList als = map.get(average);
Iterator bow = als.iterator();
int sum1,sum2,sum3;
sum1=sum2=sum3=0;

while(bow.hasNext())
{
Bowler bb = bow.next();

//caculates the average score for the bowlers
float avg = (bb.getScore1()+bb.getScore2()+bb.getScore3())/3;

//displays the bowlers number and their three scores
System.out.println("Bowler " + bb.getBowlerNumber() +" game scores are: "+bb.getScore1()+", "+bb.getScore2()+", "+bb.getScore3());

//displays the bowlers number and thier average
System.out.println("Average Score of bowler "+bb.getBowlerNumber()+" is: "+avg);

System.out.println();

sum1 = sum1 + bb.getScore1();
sum2 = sum2 + bb.getScore2();
sum3 = sum3 + bb.getScore3();
}
}

private void generateReportGT(Character GrandTotal) {
ArrayList als = map.get(GrandTotal);
Iterator bow = als.iterator();
int t = 0;
int gt = 0;
while(bow.hasNext())
{
Bowler bb = bow.next();

//adds up the bowlers scores and stores them in t
t = t + bb.getScore1()+bb.getScore2()+bb.getScore3();

//displays the bowlers number and thier three scores
System.out.println("Bowler " + bb.getBowlerNumber() +" games score are: "+bb.getScore1()+", "+bb.getScore2()+", "+bb.getScore3());

//takes the bowlers total scores and adds them all together
gt = gt + t;

//displays the total score for each bowler
System.out.println("Bowler's total score is: "+t);

System.out.println();
}

//displays the Grand total for the teams scores
System.out.println("Grand total for the team is: "+ gt);

System.out.println();
}

public void generateReport(HashMap> map) {
// Getting Key and Value from HashMap using entrySet
//Iterating each Bowler using Entry in Map
Set>> set = map.entrySet();
Iterator>> itr = set.iterator();
while(itr.hasNext()){
Entry> entry = itr.next();
this.generateReport(entry.getKey());
}
}

public void generateReportAvg(HashMap> map) {
// Getting Key and Value from HashMap using entrySet
//Iterating each Bowler using Entry in Map
Set>> set2 = map.entrySet();
Iterator>> itr2 = set2.iterator();
while(itr2.hasNext()){
Entry> entry2 = itr2.next();
this.generateReportAvg(entry2.getKey());
}
}

public void generateReportGT(HashMap> map) {
// Getting Key and Value from HashMap using entrySet
//Iterating each Bowler using Entry in Map
Set>> set3 = map.entrySet();
Iterator>> itr3 = set3.iterator();
while(itr3.hasNext()){
Entry> entry3 = itr3.next();
this.generateReportGT(entry3.getKey());
}
}
}

The code does work but I am wondering how I would be able to change the program so it doesn't use a Hashmap.

And here is the scores.txt that i forgot to put in earlier: 101, 123, 133, 165, 102, 202, 175, 220, 103, 155, 170, 140, 104, 123, 111, 99, 105, 75, 127, 133, 201, 195, 202, 187, 202, 188, 167, 175, 203, 145, 155, 165, 204, 165, 180, 133, 205, 140, 130, 125, 301, 100, 175, 90, 302, 130, 77, 120, 303, 200, 230, 193, 304, 178, 188, 193, 305, 155, 156, 157, 401, 160, 140, 155, 402, 170, 190, 185, 403, 210, 202, 233, 404, 105, 121, 133, 405, 145, 165, 185 the numbers aren't allowed to be changed in anyway once so ever either.

here is what the program should be able to do: Problem overview:
You are to write programs to help manage and provide reports for a small bowling league.
Input specifications:
Input will consist of a text file that is comma delimited. Each record will consist of bowler number, bowler first score, bowler second score, bowler third score. You are not allowed to modify the input file in any way.
Processing requirement:
Each record’s information will be used to instantiate a “Bowler” type object. The Bowler object will have the following attributes: bowlerNumber, score 1, score 2 and score 3. All attributes are to be integers. You will need to provide the ‘set’ and ‘get’ methods for each attribute. You will also need to provide at least 1 constructor method for the Bowler class.
Output specifications:
Your program needs to allow the user to choose between multiple reports.
- Display file information
- Display file information plus the average score for each bowler
- Display file information plus the team totals for each game and a grand total for the team’s series total.

Explanation / Answer

public class Bowler
{
String bowlerNumber;
int score1,score2,score3;

//gets the bowler number
public String getBowlerNumber()
{
return bowlerNumber;
}

//sets the bowler number
public void setBowlerNumber(String bowlerNumber)
{
this.bowlerNumber = bowlerNumber;
}

//gets the first score
public int getScore1()
{
return score1;
}

//sets the first score
public void setScore1(int score1)
{
this.score1 = score1;
}

//gets the second score
public int getScore2()
{
return score2;
}

//sets the second score
public void setScore2(int score2)
{
this.score2 = score2;
}

//gets the third score
public int getScore3()
{
return score3;
}

//sets the third score
public void setScore3(int score3)
{
this.score3 = score3;
}
  
}

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Scanner;
public class BowlerReports {
  
//creates an array list called Bowler
static HashMap> map;

public static void main(String args[])
{
ArrayList scores;


map = new HashMap>();
try{
  
//creates a scanner
Scanner s = new Scanner(System.in);

//opens the file Scores.txt
FileReader fr = new FileReader("Scores.txt");

//Reads the file
BufferedReader br= new BufferedReader(fr);
String line;

//creates a string buffer
StringBuffer sb = new StringBuffer();

//stores all of the info from the file into line
while((line=br.readLine())!=null)
{
sb.append(line);
}

//Converting into string and splitting using comma
String data[] = sb.toString().split("," + " ");
int i = 0;
Bowler b;
  
while(data.length > i)
{
//stores the Bowler array list in scores
scores = new ArrayList();
b = new Bowler();
b.setBowlerNumber(data[i]);

//takes all of the bowlers that have a number in the 100s
b.setScore1(Integer.parseInt(data[i+1]));

//takes all of the bowlers that have a number in the 200s
b.setScore2(Integer.parseInt(data[i+2]));

//takes all of the bowlers that have a number in the 300s
b.setScore3(Integer.parseInt(data[i+3]));

//takes all of the bowler that have a number in the 400s
i=i+4;

scores.add(b);

//adds the number to the list according to the number it starts with
if(map.containsKey(b.getBowlerNumber().charAt(0))){
ArrayList sl = map.get(b.getBowlerNumber().charAt(0));
sl.add(b);
map.put(b.getBowlerNumber().charAt(0), sl);
}

else
{
//adds the number normally
map.put(b.getBowlerNumber().charAt(0),scores);
}
}

BowlerReports bReport = new BowlerReports();

int j = 0;
while(j == 0)
{
//asks the user to select what report they would like
System.out.println("Please select what report you would like");

System.out.println("1. A report with all of the bowlers and their scores");

System.out.println("2. A report with all of the bowlers scores and their averages");

System.out.println("3. A repot with all of the bowlers and their team totals");

System.out.println("4. To exit the program");

//creates a scanner to record the users input
Scanner sc = new Scanner(System.in);

//stores the users input
int choice = sc.nextInt();

//chooses what to do with the users input
switch(choice)
{
//shows the Bowlers numbers and scores
case 1: bReport.generateReport(map);
break;
  
//shows the Bowlers scores and average scores
case 2: bReport.generateReportAvg(map);
break;
  
//shows the Bowlers scores and their team scores
case 3: bReport.generateReportGT(map);
break;

// exits the program
case 4: j = 1;
System.out.println("See ya later!");
break;
  
//if the user enters an invalid entry then it propmts them to enter in the correct entry
default: System.out.println("A number between 1 and 4");
}   
}
}
catch(Exception e)
{
e.printStackTrace();
}
  
}

private void generateReport(Character teamName)
{
ArrayList als = map.get(teamName);
Iterator bow = als.iterator();

while(bow.hasNext())
{
Bowler bb = bow.next();
  
//shows the bowler number and their three scores
System.out.println("Bowler " + bb.getBowlerNumber() + " scores are: " +" "+bb.getScore1()+", "+bb.getScore2()+", "+bb.getScore3());

System.out.println();
}
}

private void generateReportAvg(Character average)
{
ArrayList als = map.get(average);
Iterator bow = als.iterator();
int sum1,sum2,sum3;
sum1=sum2=sum3=0;

while(bow.hasNext())
{
Bowler bb = bow.next();

//caculates the average score for the bowlers
float avg = (bb.getScore1()+bb.getScore2()+bb.getScore3())/3;

//displays the bowlers number and their three scores
System.out.println("Bowler " + bb.getBowlerNumber() +" game scores are: "+bb.getScore1()+", "+bb.getScore2()+", "+bb.getScore3());

//displays the bowlers number and thier average
System.out.println("Average Score of bowler "+bb.getBowlerNumber()+" is: "+avg);

System.out.println();

sum1 = sum1 + bb.getScore1();
sum2 = sum2 + bb.getScore2();
sum3 = sum3 + bb.getScore3();
}
}

private void generateReportGT(Character GrandTotal) {
ArrayList als = map.get(GrandTotal);
Iterator bow = als.iterator();
int t = 0;
int gt = 0;
while(bow.hasNext())
{
Bowler bb = bow.next();

//adds up the bowlers scores and stores them in t
t = t + bb.getScore1()+bb.getScore2()+bb.getScore3();

//displays the bowlers number and thier three scores
System.out.println("Bowler " + bb.getBowlerNumber() +" games score are: "+bb.getScore1()+", "+bb.getScore2()+", "+bb.getScore3());

//takes the bowlers total scores and adds them all together
gt = gt + t;

//displays the total score for each bowler
System.out.println("Bowler's total score is: "+t);

System.out.println();
}

//displays the Grand total for the teams scores
System.out.println("Grand total for the team is: "+ gt);

System.out.println();
}

public void generateReport(HashMap> map) {
// Getting Key and Value from HashMap using entrySet
//Iterating each Bowler using Entry in Map
Set>> set = map.entrySet();
Iterator>> itr = set.iterator();
while(itr.hasNext()){
Entry> entry = itr.next();
this.generateReport(entry.getKey());
}
}

public void generateReportAvg(HashMap> map) {
// Getting Key and Value from HashMap using entrySet
//Iterating each Bowler using Entry in Map
Set>> set2 = map.entrySet();
Iterator>> itr2 = set2.iterator();
while(itr2.hasNext()){
Entry> entry2 = itr2.next();
this.generateReportAvg(entry2.getKey());
}
}

public void generateReportGT(HashMap> map) {
// Getting Key and Value from HashMap using entrySet
//Iterating each Bowler using Entry in Map
Set>> set3 = map.entrySet();
Iterator>> itr3 = set3.iterator();
while(itr3.hasNext()){
Entry> entry3 = itr3.next();
this.generateReportGT(entry3.getKey());
}
}
}