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

(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 team = new ArrayList();

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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!