Note that there are some explanatory texts on larger screens.

plurals
  1. POReading every other line from a txt file and saving into an array
    primarykey
    data
    text
    <p>assignment: A school that your little cousin attends is selling cookies. If your cousin's class sells more cookies than any other class, the teacher has promised to take the whole class on a picnic. Of course, your cousin volunteered you to keep track of all the sales and determine the winner.</p> <p>Each class is identified by the teacher's name. Each sales slip has the teacher's name and the number of boxes sold. You decide to create two parallel arrays: one to hold the teacher's names and one to record the number of boxes sold. Here is a sample of the data:</p> <p>The first number gives the number of classes, and then a teacher's Name is followed by the number of boxes sold 15 Smith 3 Courtney ... so on so forth<br> <br><br> My main issue (because i can just duplicate it for the "to-be" parrallel array) is getting every other line to save into an array for the boxes sold so array "boxSold" would look like <br><br> [1] 15 <br> [2] 3</p> <pre><code> package assignment5Package; import java.util.Scanner; import java.io.*; public class assignment5Demo { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub //create arrays, variables Scanner keyboard = new Scanner(System.in); BufferedReader input = new BufferedReader (new FileReader ("/Users/lee/Desktop/class/cs 113/Assignment5/cookies.txt")); System.out.println("How many sale slips are there"); int numSaleSlips = keyboard.nextInt(); int[] soldBox = new int[numSaleSlips]; //______String[] teacherName = new String[numSaleSlips]; int soldBoxIndex; int teacherNameIndex; //String soldBoxString; (line 50) //initializing both strings to 0 and "_" for (soldBoxIndex = 0; soldBoxIndex &lt; numSaleSlips; soldBoxIndex++) { soldBox[soldBoxIndex] = 0; } //**for (teacherNameIndex = 0; teacherNameIndex &lt; numSaleSlips; teacherNameIndex++) //**{ //** teacherName[teacherNameIndex] = "_"; //**} //reading from the cookies.txt file for (soldBoxIndex = 0; soldBoxIndex &lt; numSaleSlips; soldBoxIndex++) { if (soldBoxIndex % 2 != 0 { String soldBoxString; soldBoxString = input.readLine(); //reads in value and assigns/re-assigns soldBox[numSaleSlips] = (int) Double.parseDouble(soldBoxString); //type-casted to fit variable type, converts to double, stores in array System.out.println(soldBox[soldBoxIndex]); } else { System.out.println("Error at " + soldBoxIndex +"."); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload