that looks like an unclosed element playboy<redacted>
public static void main(String[] args) throws FileNotFoundException{
int[] firstyr = new int[15];
int[] lastyr = new int[15];
String[] title = new String[15];
String[] network = new String[15];
Scanner input = new Scanner(new File("tvshows.txt"));
int totalShows = 0;
int i = 0;
while(input.hasNextLine()) {
String line = input.nextLine();
Scanner lineScan = new Scanner(line);
firstyr[i] = lineScan.nextInt();
lastyr[i] = lineScan.nextInt();
title[i] = lineScan.next();
network[i] = lineScan.next();
i++;
totalShows++;
}
}// end main
you'll come back stronger! if it was easy everyone would do it@Obreh Winfrey
I bombed my java written final so bad. I can't believe I just went blank I still can't figure out how to get pass the first section of the final. I couldn't populate a 4 arrays ( 2 in, 2 string) from a text file. I spent the whole 1 hour 30 minuites trying to do this task.
Code:public static void main(String[] args) throws FileNotFoundException{ int[] firstyr = new int[15]; int[] lastyr = new int[15]; String[] title = new String[15]; String[] network = new String[15]; Scanner input = new Scanner(new File("tvshows.txt")); int totalShows = 0; int i = 0; while(input.hasNextLine()) { String line = input.nextLine(); Scanner lineScan = new Scanner(line); firstyr[i] = lineScan.nextInt(); lastyr[i] = lineScan.nextInt(); title[i] = lineScan.next(); network[i] = lineScan.next(); i++; totalShows++; } }// end main
I still haven't grasped the concept of file processing and arrays. At least the written part didn't bring down my final grade too much
This is true but frustrating as hell.you'll come back stronger! if it was easy everyone would do it
That looks like it should work. Is that what you wrote down or was that from after the fact? Arrays get easier. File operations always suck.@Obreh Winfrey
I bombed my java written final so bad. I can't believe I just went blank I still can't figure out how to get pass the first section of the final. I couldn't populate a 4 arrays ( 2 in, 2 string) from a text file. I spent the whole 1 hour 30 minuites trying to do this task.
Code:public static void main(String[] args) throws FileNotFoundException{ int[] firstyr = new int[15]; int[] lastyr = new int[15]; String[] title = new String[15]; String[] network = new String[15]; Scanner input = new Scanner(new File("tvshows.txt")); int totalShows = 0; int i = 0; while(input.hasNextLine()) { String line = input.nextLine(); Scanner lineScan = new Scanner(line); firstyr[i] = lineScan.nextInt(); lastyr[i] = lineScan.nextInt(); title[i] = lineScan.next(); network[i] = lineScan.next(); i++; totalShows++; } }// end main
I still haven't grasped the concept of file processing and arrays. At least the written part didn't bring down my final grade too much
Yes, that is what I turned in.That looks like it should work. Is that what you wrote down or was that from after the fact? Arrays get easier. File operations always suck.
@Obreh Winfrey
I bombed my java written final so bad. I can't believe I just went blank I still can't figure out how to get pass the first section of the final. I couldn't populate a 4 arrays ( 2 in, 2 string) from a text file. I spent the whole 1 hour 30 minuites trying to do this task.
Code:public static void main(String[] args) throws FileNotFoundException{ int[] firstyr = new int[15]; int[] lastyr = new int[15]; String[] title = new String[15]; String[] network = new String[15]; Scanner input = new Scanner(new File("tvshows.txt")); int totalShows = 0; int i = 0; while(input.hasNextLine()) { String line = input.nextLine(); Scanner lineScan = new Scanner(line); firstyr[i] = lineScan.nextInt(); lastyr[i] = lineScan.nextInt(); title[i] = lineScan.next(); network[i] = lineScan.next(); i++; totalShows++; } }// end main
I still haven't grasped the concept of file processing and arrays. At least the written part didn't bring down my final grade too much
Yep intro to computer science course, I froze hence nothing printing out. I'm just mad that I didn't know how to do what was on the test. Hopefully, I can grasp the concepts for data structures next semester.I don't remember Java that much, if this is 101 course and your professor ain't caring about effiency. just do 4 loops. This program would not output anything regardless. I'm 80% sure you don't need 2 scanners.
Yes, that is what I turned in.
That was just the first section of the test. the file looked like this
1989 1997 Coach ABC
but 14 more lines. the next section was to call a method named printSentences using the arrays as parameters and also sending the array size to print out all 15 entries in the array. couldn't even get to that point. The rest of the final had you pushing and popping certain arrays and along with other stuff. I just feel defeated. I hate these damn arrays and getting out of bound errors.
Stage 1: 3 pts Stage 2: 10 pts Stage 3: 1 pt (no code) Stage 4: 0 pts Stage 5: 0 pts Stage 6: 0 pts Compile: 10 pts Run: 5 pts (there was no output; I gave you this much because you at least read data from the file). Bonus: 0 pts Total: 29 pts
import java.util.Scanner;
public class MyClass() {
public static void main(String[] args) throws FileNotFoundException {
int[] firstyr = new int[15];
int[] lastyr = new int[15];
String[] title = new String[15];
String[] network = new String[15];
Scanner input = new Scanner(new File("tvshows.txt"));
int totalShows = 0;
int i = 0;
while(input.hasNextLine()) {
String line = input.nextLine(); // 1989 1997 Coach ABC
String[] fields = line.split(); // [ "1989", "1997", "Coach", "ABC" ]
firstyr[i] = fields[0]; //1989
lastyr[i] = fields[1]; //1997
title[i] = fields[2]; //Coach
network[i] = fields[3]; //ABC
i++;
}
input.close(); // Should always close your Scanner
printSentences(firstyr, lastyr, title, network);
}// end main
public static void printSentences(int[] firstyr, int[] lastyr, String[] title, String[] network) {
for(int i = 0; i < firstyr.length - 1; i++) { //assuming they'll always be the same length
System.out.printf("%s aired from %d to %d on %s.\n", title[i] , firstyr[i] , lastyr[i] ,network[i]);
}
}
}