Results 1 to 10 of 10
- 06-05-2008, 09:42 PM #1
Member
- Join Date
- Apr 2008
- Posts
- 88
- Rep Power
- 0
[SOLVED] File I/O Extra Credit Assignment FTW!
Hey guys, if you can help me work through this ill love you forever and im even willing to donate money to this site because its been so helpful!
This is the extra credit assignment that may save my grade and I have a slight idea of how to start but i wanna make sure I get off to a CORRECT start.
So we're suppose to have a Student and Controller Class
Now to start off the student class would probably be best. Am I correct in stating that the student class is to create a constructor for student to hold information about EACH student? Could someone give me an idea of how many variables I would need to hold the sufficient information.Or would the variables just include things like string Quiz1, string Quiz2, up to String xCred3?
Please see below for details regarding the assignment, then my question should make a little more sense lol
This is our assignment:
Write a program that will read a text file of students (the number of students can vary) and their corresponding grades for each assignemnt including extra
credit assignments / points.
Use a student class and a controller class
10 pts: The program outputs the grade of each student see example
10 pts: The program outputs the ranking of the student in the class.
10 pts: The program outputs output how many students got an A, how many got a B and how many got a C.
Use our current CIS234 class assignments to model your program. Use your scores as one of the student examples, and generate some sample data for
other students.
See attached file for sample file input and output.
Possible Points
Possible Total 500 pts Possible Total Extra Credit 45 pts
Assignment Quiz1 Quiz2 Quiz3 Project1 Project2 Project3 Midterm Final Attendance Xcredit1 Xcredit2 Xcredit3
Points 10 10 10 60 80 80 100 150 5 7 15 18
Test Data
Quiz1 Quiz2 Quiz3 Project1 Project2 Project3 Midterm Final Attendance Xcredit1 Xcredit2 Xcredit3
Homer
Simpson
8 6 7 53 45 70 81 119 0 5 7 6
Bart
Simpson
5 3 6 45 51 62 90 100 0 3 6 2
Lisa
Simpson
7 5 3 59 49 69 92 135 5 7 7 7
Calculations:
Grade = ((Sum(Assignments) + (Sum Extra Credit)) / 500) * 100
Letter Grade:
90% <= Grade A
80% <= Grade < 90% B
70% <= Grade < 80% C
70% > Grade F
Output example: (in a JOptionPane window)
Grade for each student:
Name: Homer Simpson, Total Points: 407, Grade: 81.4, Letter Grade: B
Name: Bart Simpson, Total Points: 373, Grade: 74.6, Letter Grade: C
Name: Lisa Simpson, Total Points: 445, Grade: 89, Letter Grade: B
Ranking of Students:
Ranking 1: Homer Simpson, Lisa Simpson
Ranking 2: Bart Simpson
Number of Students for each grade:
Number of A students: 0
Number of B students: 2
Number of C students: 1
Number of F students: 0
- 06-05-2008, 11:50 PM #2
Now to start off the student class would probably be best.
Agreed.
Am I correct in stating that the student class is to create a constructor for student to hold information about EACH student?
Not exactly. The Student class can and probably should (logically would) have a constructor that is used to build the class. Typically, the constructor is where and how we pass the information/values into/to the class which it needs/uses for initialization, viz, to initialize its fields, aka, member variables.
For example, if I make up a class with two fields and initialize them through a constructor it might look like this:
// Creat an instance of Pseudo and sace a reference to it (the newly created object) in a variable named "pseudo":Java Code:class Pseudo { Date today; String subject; public Pseudo(Date date, String subject) { today = date; this.subject = subject; } }
Now it is more accurate to say that the class instance will hold the values I gave it for initialization when I instantiated (created) it with the new operator.Java Code:Pseudo pseudo = new Pseudo(Calendar.getInstance().getTime(), "constructors"); // What's the subject of "pseudo?" System.out.println("pseudo's subject = " + pseudo.subject);
For more on constructors see Providing Constructors for Your Classes.
Could someone give me an idea of how many variables I would need to hold the sufficient information.
The assignment lists them explicitly, under "Test Data":
Quiz1 Quiz2 Quiz3 Project1 Project2 Project3 Midterm Final Attendance Xcredit1 Xcredit2 Xcredit3
12 total. Each example file has that many integers in it. So you'll need to make arrangements to accept and store (with member variables) each of these in your Strudent class.
Or would the variables just include things like string Quiz1, string Quiz2, up to String xCred3?
Yes.
- 06-06-2008, 12:58 AM #3
Member
- Join Date
- Apr 2008
- Posts
- 88
- Rep Power
- 0
Thank you I'll try to finish the student class and ask you guys if it looks correct! :)
- 06-07-2008, 04:32 AM #4
Member
- Join Date
- Apr 2008
- Posts
- 88
- Rep Power
- 0
Hows this look for the student class?
Java Code:package extracredit; public class Student { private int Quiz1; private int Quiz2; private int Quiz3; private int Project1; private int Project2; private int Project3; private int Midterm; private int Final; private int Attendance; private int extraCredit1; private int extraCredit2; private int extraCredit3; public Student(int aQuiz1, int aQuiz2, int aQuiz3, int aProject1, int aProject2, int aProject3, int aMidterm, int aFinal, int aAttendance, int aExtraCredit1, int aExtraCredit2, int aExtraCredit3){ Quiz1 = aQuiz1; Quiz2 = aQuiz2; Quiz3 = aQuiz3; Project1 = aProject1; Project2 = aProject2; Project3 = aProject3; Midterm = aMidterm; Final = aFinal; Attendance = aAttendance; extraCredit1 = aExtraCredit1; extraCredit2 = aExtraCredit2; extraCredit3 = aExtraCredit3; } public int getQuiz1(){ return Quiz1; } public int getQuiz2(){ return Quiz2; } public int getQuiz3(){ return Quiz3; } public int getProject1(){ return Project1; } public int getProject2(){ return Project2; } public int getProject3(){ return Project3; } public int getMidterm(){ return Midterm; } public int getFinal(){ return Final; } public int getAttendance(){ return Attendance; } public int getExtraCredit1(){ return extraCredit1; } public int getExtraCredit2(){ return extraCredit2; } public int getExtraCredit3(){ return extraCredit3; } }
-
This statement:
suggests that your Student class is going to have to have some additional methods too. What do you think that they should be, what should each method return (i.e., int, String, double,...), and what code should go in the methods?Grade for each student:
Name: Homer Simpson, Total Points: 407, Grade: 81.4, Letter Grade: B
Name: Bart Simpson, Total Points: 373, Grade: 74.6, Letter Grade: C
Name: Lisa Simpson, Total Points: 445, Grade: 89, Letter Grade: B
- 06-07-2008, 06:17 AM #6
Member
- Join Date
- Apr 2008
- Posts
- 88
- Rep Power
- 0
Looks like I should change everything to a double to be safe (looking at grade). The funny thing is the teacher has a very similar example for us in a file that takes a file, splits it up into lines and reads the lines of a text file and outputs them but what makes this difficult for me is having to use 2 separate classes.
I dont understand what else should be done in the methods, we dont use a get and call it from the controller class?
- 06-08-2008, 07:38 AM #7
Member
- Join Date
- Jun 2008
- Posts
- 1
- Rep Power
- 0
Hm, I have a similar project to this one. I need help too!
It will be much appreciated. Thanks in advance.
/Steve
- 06-08-2008, 11:02 AM #8
Member
- Join Date
- Apr 2008
- Posts
- 88
- Rep Power
- 0
Before you guys answer my question please wait, I have much updated code to put here and new questions, I can get the output to come out correctly I just cant get it all in one screen and to properly accumlate the number of A grades, B grades, etc.
- 06-08-2008, 08:31 PM #9
Member
- Join Date
- Apr 2008
- Posts
- 88
- Rep Power
- 0
Ok if someone could please help me figure out whats wrong Id really appreciate it, here is my updated code which calculates the grades properly according to their scores (in a text file each student is seperated by lines like Homer Simpson 5 5 10 5, etc) and then the program reads each line and outputs the person with their score, grade in percentage, grade in letter, etc.
The problem is I want everyone's summary to show up in one window instead of separately, any ideas?
Java Code:public static void main(String[] args){ StringTokenizer st; String line; try { //create a filereader FileReader fr = new FileReader(new File("c:\\grades.csv")); //create a bufferedreader BufferedReader bf = new BufferedReader(fr); //loop and read each line from the file as long //as the data read is not null while ((line = bf.readLine()) != null) { //break up the line using a string tokenizer st = new StringTokenizer(line, ","); String name = st.nextToken(); String quiz1 = st.nextToken(); double aQuiz1 = Double.parseDouble(quiz1); String quiz2 = st.nextToken() ; double aQuiz2 = Double.parseDouble(quiz2); String quiz3 = st.nextToken(); double aQuiz3 = Double.parseDouble(quiz3); String project1 = st.nextToken(); double aProject1 = Double.parseDouble(project1); String project2 = st.nextToken(); double aProject2 = Double.parseDouble(project2); String project3 = st.nextToken(); double aProject3 = Double.parseDouble(project3); String midterm = st.nextToken(); double aMidterm = Double.parseDouble(midterm); String testFinal = st.nextToken(); double aTestFinal = Double.parseDouble(testFinal); String attendance = st.nextToken(); double aAttendance = Double.parseDouble(attendance); String extraCredit1 = st.nextToken(); double aExtraCredit1 = Double.parseDouble(extraCredit1); String extraCredit2 = st.nextToken(); double aExtraCredit2 = Double.parseDouble(extraCredit2); String extraCredit3 = st.nextToken(); double aExtraCredit3 = Double.parseDouble(extraCredit3); double assignSum = (aQuiz1 + aQuiz2 + aQuiz3 + aProject1 + aProject2 + aProject3 + aMidterm + aTestFinal + aAttendance); double extraSum = (aExtraCredit1 + aExtraCredit2 + aExtraCredit3); double total = assignSum + extraSum; double grade = ((assignSum + extraSum)/500) * 100; int gradeA = 0; int gradeB = 0; int gradeC = 0; int gradeF = 0; String letterGrade = ""; if (grade >= 90) {letterGrade = "A"; ++gradeA;} if (grade >= 80 && grade < 90 ) {letterGrade = "B"; ++gradeB;} if (grade >= 70 && grade < 80) {letterGrade = "C"; ++gradeC;} if (grade < 70) { letterGrade = "F"; ++gradeF;} Student student = new Student(name, quiz1, quiz2, quiz3, project1, project2, project3, midterm, testFinal, attendance, extraCredit1, extraCredit2, extraCredit3, total, grade, letterGrade, gradeA, gradeB ,gradeC, gradeF); JOptionPane.showMessageDialog(null, student.toString()); JOptionPane.showMessageDialog(null, student.toStrings()); //use a while loop to print all tokens //check if the string tokenizer has more tokens //then print them while (st.hasMoreTokens()) { System.out.print(st.nextToken() + " "); } //print a line break System.out.print("\n"); } //close the buffered reader bf.close(); //close the filereader fr.close(); } catch (Exception e) { //print any errors e.printStackTrace(); } } }
- 06-10-2008, 08:20 AM #10
Member
- Join Date
- Apr 2008
- Posts
- 88
- Rep Power
- 0
Similar Threads
-
Extra bracket
By CrazyShells Slam in forum New To JavaReplies: 5Last Post: 05-16-2008, 06:12 AM -
Java assignment
By xtianah77 in forum New To JavaReplies: 1Last Post: 02-17-2008, 11:54 PM -
for Assignment plz help
By assamhammad in forum New To JavaReplies: 1Last Post: 11-06-2007, 08:35 PM -
java assignment, need help bad.
By carlos123 in forum New To JavaReplies: 1Last Post: 11-06-2007, 04:53 PM -
Help with my assignment java
By toby in forum New To JavaReplies: 1Last Post: 08-07-2007, 05:59 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks