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

(JAVA QUESTION) Need help with using a loop to go through the arraylist and get

ID: 3723573 • Letter: #

Question

(JAVA QUESTION)

Need help with using a loop to go through the arraylist and get the team totals OF THE NUMBER OF POINTS (which is 2 * the number they made) //print out totals etc.. EX: 2* twoMade;

import java.util.ArrayList;

import java.util.Scanner;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.PrintWriter;

import java.io.FileOutputStream;

public class fileStreamtest {

public static void main(String [ ] args) {

Scanner inputStream=null;

PrintWriter outputStream=null;

ArrayList<BBall> team = new ArrayList<BBall>();

   try {

inputStream= new Scanner ( new FileInputStream("/Users/Gracie/Documents/workspace/Lab7/src/team.txt"));

outputStream = new PrintWriter( new FileOutputStream("/Users/Gracie/Documents/workspace/Lab7/src/team_stat.txt"));

   }

   catch (FileNotFoundException e) {

System.out.println("Problem opening files" + e.toString());

System.exit(0);

   }

   //Here you declare and initialize the varibales you need in loop

   int num;

   String fname;

   String lname;

   int twoMade;

   int twoAttempt;

   int threeMade;

   int threeAttempt;

   int foulMade;

   int foulAttempt;

   while (inputStream.hasNextLine( ) ) {

// read variable by variable across the line

num =inputStream.nextInt();

lname =inputStream.next();

fname = inputStream.next();

twoMade = inputStream.nextInt();

twoAttempt = inputStream.nextInt();

threeMade = inputStream.nextInt();

threeAttempt = inputStream.nextInt();

foulMade = inputStream.nextInt();

foulAttempt = inputStream.nextInt();

  

BBall player = new BBall(num, fname, lname, twoMade, twoAttempt, threeMade, threeAttempt, foulMade, foulAttempt);

team.add(player);

//THE PART I AM STUCK ON

// using a loop go through the arraylist and get the team totals OF THE NUMBER OF POINTS

   //print out totals etc

  

Explanation / Answer

The relevant code:

for (int i = 0; i<team.size(); i++){
    System.out.println("Team :" + team.get(i).getNum())
    int points = 2 * (team.get(i).getTwoMade() + team.get(i).getThreeMade());
    System.out.println("Total Points:" + points);
    System.out.println("---------------------------------------------");
}