Código:
import java.io.*; // needed for file and I/O classes
import java.util.*;
public class Assigment4
{
public static void main(String[] args) throws IOException
{
int count = 0;
int A = 0, AM = 0, B = 0, BM = 0, BP = 0, C = 0, CP = 0, D = 0, DP = 0, F = 0, I = 0, W = 0, transfer = 0, passing = 0;
String fileName; // to hold the file name
ArrayList<String> courseNo = new ArrayList<String>();
ArrayList<String> departCode = new ArrayList<String>();
ArrayList<String> department = new ArrayList<String>();
ArrayList<String> courseName = new ArrayList<String>();
ArrayList<String> course = new ArrayList<String>();
ArrayList<String> grade = new ArrayList<String>();
ArrayList<String> sectionNo = new ArrayList<String>();
String blank = "";
String blank2 = "";
//create a scanner object for keyboard input
Scanner keyboard = new Scanner(System.in);
// get the file name
//System.out.print("Enter the name of the file: ");
fileName = "Grades.txt";
//fileName = keyboard.nextLine();
// open the file
File theFile = new File(fileName);
//create a scanner object for to read the file
Scanner inputFile = new Scanner(theFile);
// use a while loop that types the document information
while(inputFile.hasNext())
{
blank = "";
blank2 = "";
//assign every document data to a different variable
courseNo.add(inputFile.next());
departCode.add(inputFile.next());
department.add(inputFile.next());
courseName.add(inputFile.next());
course.add(inputFile.next());
grade.add(inputFile.next());
sectionNo.add(inputFile.next());
blank = inputFile.nextLine();
blank2 = inputFile.nextLine();
if(!blank2.equals("") )
{
department.add(count, courseName.get(count) );
courseName.set(count, course.get(count) );
courseName.add(count, grade.get(count) );
course.set(count, sectionNo.get(count) );
grade.set(count, blank);
sectionNo.set(count, blank2);
}
else if(!blank.equals("") )
{
courseName.add(count, course.get(count) );
course.set(count, grade.get(count) );
grade.set(count, sectionNo.get(count) );
sectionNo.set(count, blank);
}
inputFile.nextLine();
count++;
}
for(int i = 0; i < count; i++)
{
if(grade.get(i).equals("A") )
A++;
else if(grade.get(i).equals("A-") )
AM++;
else if(grade.get(i).equals("B") )
B++;
else if(grade.get(i).equals("B-") )
BM++;
else if(grade.get(i).equals("B+") )
BP++;
else if(grade.get(i).equals("C") )
C++;
else if(grade.get(i).equals("C+") )
CP++;
else if(grade.get(i).equals("D") )
D++;
else if(grade.get(i).equals("D+") )
DP++;
else if(grade.get(i).equals("F") )
F++;
else if(grade.get(i).equals("I") )
I++;
else if(grade.get(i).equals("W") )
W++;
else if(grade.get(i).equals("Transfer") )
transfer++;
else if(grade.get(i).equals("Passing") )
passing++;
}
//for(int i = 0; i < count; i++)
// System.out.println(grade.get(i) );
System.out.printf("%-10s %-5s %2s %s %s %s %s %s %s %s %s %s %s %s %s %s %s", "Course No.", "Subject",
"Course", "Course Title", "A", "A-", "B", "B-", "B+","C", "C+", "D", "D+", "F", "I", "W", "Transfer", "Passing\n" );
for(int i = 0; i < count; i++)
{
System.out.printf("%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s", courseNo.get(i),
departCode.get(i), department.get(i), courseName.get(i), course.get(i), grade.get(i), sectionNo.get(i));
}
}
}
este es el documento
Citar
4750 ACC Accounting Business Accounting ACC101 A- 001
4750 ACC Accounting Business Accounting ACC101 B+ 001
4750 ACC Accounting Business Accounting ACC101 B- 001
4750 ACC Accounting Business Accounting ACC101 A 001
4750 ACC Accounting Business Accounting ACC101 A 001
4750 ACC Accounting Business Accounting ACC101 B+ 001
4750 ACC Accounting Business Accounting ACC101 A- 001
4750 ACC Accounting Business Accounting ACC101 A 001
4750 ACC Accounting Business Accounting ACC101 A 001
4750 ACC Accounting Business Accounting ACC101 F 001
4750 ACC Accounting Business Accounting ACC101 A 001
4750 ACC Accounting Business Accounting ACC101 C+ 001
4750 ACC Accounting Business Accounting ACC101 A 001
3157 BIO Biology Anatomy BIO320 A 001
3157 BIO Biology Anatomy BIO320 W 001
3157 BIO Biology Anatomy BIO320 D+ 001
3157 BIO Biology Anatomy BIO320 D 001
3157 BIO Biology Anatomy BIO320 F 001
3157 BIO Biology Anatomy BIO320 B 001
3157 BIO Biology Anatomy BIO320 A- 001
3157 BIO Biology Anatomy BIO320 A- 001
3157 BIO Biology Anatomy BIO320 A 001
3157 BIO Biology Anatomy BIO320 B- 001
3157 BIO Biology Anatomy BIO320 A 001
3157 BIO Biology Anatomy BIO320 C 001
3157 BIO Biology Anatomy BIO320 A 001
3157 BIO Biology Anatomy BIO320 C+ 001
3494 BUS Business Marketing Fundamentals BUS251 C 006
3494 BUS Business Marketing Fundamentals BUS251 A 006
3494 BUS Business Marketing Fundamentals BUS251 A- 006
3494 BUS Business Marketing Fundamentals BUS251 D 006
3494 BUS Business Marketing Fundamentals BUS251 A 006
3494 BUS Business Marketing Fundamentals BUS251 A- 006
3494 BUS Business Marketing Fundamentals BUS251 B+ 006
3494 BUS Business Marketing Fundamentals BUS251 B- 006
3494 BUS Business Marketing Fundamentals BUS251 A- 006
4612 CMP Computer Science Java I CMP110 A- 010
4612 CMP Computer Science Java I CMP110 B 010
4612 CMP Computer Science Java I CMP110 A- 010
4612 CMP Computer Science Java I CMP110 A- 010
4612 CMP Computer Science Java I CMP110 A 010
4612 CMP Computer Science Java I CMP110 D 010
4612 CMP Computer Science Java I CMP110 B+ 010
4612 CMP Computer Science Java I CMP110 B 010
4612 CMP Computer Science Java I CMP110 A 010
4612 CMP Computer Science Java I CMP110 A- 010
4188 CMP Computer Science Operating Systems CMP320 C 106
4188 CMP Computer Science Operating Systems CMP320 A- 106
4188 CMP Computer Science Operating Systems CMP320 A- 106
4188 CMP Computer Science Operating Systems CMP320 B+ 106
4188 CMP Computer Science Operating Systems CMP320 A 106
4188 CMP Computer Science Operating Systems CMP320 D+ 106
4188 CMP Computer Science Operating Systems CMP320 A 106
4188 CMP Computer Science Operating Systems CMP320 W 106
4750 ACC Accounting Business Accounting ACC101 B+ 001
4750 ACC Accounting Business Accounting ACC101 B- 001
4750 ACC Accounting Business Accounting ACC101 A 001
4750 ACC Accounting Business Accounting ACC101 A 001
4750 ACC Accounting Business Accounting ACC101 B+ 001
4750 ACC Accounting Business Accounting ACC101 A- 001
4750 ACC Accounting Business Accounting ACC101 A 001
4750 ACC Accounting Business Accounting ACC101 A 001
4750 ACC Accounting Business Accounting ACC101 F 001
4750 ACC Accounting Business Accounting ACC101 A 001
4750 ACC Accounting Business Accounting ACC101 C+ 001
4750 ACC Accounting Business Accounting ACC101 A 001
3157 BIO Biology Anatomy BIO320 A 001
3157 BIO Biology Anatomy BIO320 W 001
3157 BIO Biology Anatomy BIO320 D+ 001
3157 BIO Biology Anatomy BIO320 D 001
3157 BIO Biology Anatomy BIO320 F 001
3157 BIO Biology Anatomy BIO320 B 001
3157 BIO Biology Anatomy BIO320 A- 001
3157 BIO Biology Anatomy BIO320 A- 001
3157 BIO Biology Anatomy BIO320 A 001
3157 BIO Biology Anatomy BIO320 B- 001
3157 BIO Biology Anatomy BIO320 A 001
3157 BIO Biology Anatomy BIO320 C 001
3157 BIO Biology Anatomy BIO320 A 001
3157 BIO Biology Anatomy BIO320 C+ 001
3494 BUS Business Marketing Fundamentals BUS251 C 006
3494 BUS Business Marketing Fundamentals BUS251 A 006
3494 BUS Business Marketing Fundamentals BUS251 A- 006
3494 BUS Business Marketing Fundamentals BUS251 D 006
3494 BUS Business Marketing Fundamentals BUS251 A 006
3494 BUS Business Marketing Fundamentals BUS251 A- 006
3494 BUS Business Marketing Fundamentals BUS251 B+ 006
3494 BUS Business Marketing Fundamentals BUS251 B- 006
3494 BUS Business Marketing Fundamentals BUS251 A- 006
4612 CMP Computer Science Java I CMP110 A- 010
4612 CMP Computer Science Java I CMP110 B 010
4612 CMP Computer Science Java I CMP110 A- 010
4612 CMP Computer Science Java I CMP110 A- 010
4612 CMP Computer Science Java I CMP110 A 010
4612 CMP Computer Science Java I CMP110 D 010
4612 CMP Computer Science Java I CMP110 B+ 010
4612 CMP Computer Science Java I CMP110 B 010
4612 CMP Computer Science Java I CMP110 A 010
4612 CMP Computer Science Java I CMP110 A- 010
4188 CMP Computer Science Operating Systems CMP320 C 106
4188 CMP Computer Science Operating Systems CMP320 A- 106
4188 CMP Computer Science Operating Systems CMP320 A- 106
4188 CMP Computer Science Operating Systems CMP320 B+ 106
4188 CMP Computer Science Operating Systems CMP320 A 106
4188 CMP Computer Science Operating Systems CMP320 D+ 106
4188 CMP Computer Science Operating Systems CMP320 A 106
4188 CMP Computer Science Operating Systems CMP320 W 106