Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-05-2008, 10:42 PM
Member
 
Join Date: Apr 2008
Posts: 77
Bascotie is on a distinguished road
[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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-06-2008, 12:50 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,144
hardwired is on a distinguished road
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:
Code:
class Pseudo { Date today; String subject; public Pseudo(Date date, String subject) { today = date; this.subject = subject; } }
// Creat an instance of Pseudo and sace a reference to it (the newly created object) in a variable named "pseudo":
Code:
Pseudo pseudo = new Pseudo(Calendar.getInstance().getTime(), "constructors"); // What's the subject of "pseudo?" System.out.println("pseudo's subject = " + pseudo.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.
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-06-2008, 01:58 AM
Member
 
Join Date: Apr 2008
Posts: 77
Bascotie is on a distinguished road
Thank you I'll try to finish the student class and ask you guys if it looks correct!
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 06-07-2008, 05:32 AM
Member
 
Join Date: Apr 2008
Posts: 77
Bascotie is on a distinguished road
Hows this look for the student class?

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; } }
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 06-07-2008, 06:20 AM
Senior Member
 
Join Date: Jun 2008
Posts: 194
Fubarable is on a distinguished road
This statement:
Quote:
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
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?
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 06-07-2008, 07:17 AM
Member
 
Join Date: Apr 2008
Posts: 77
Bascotie is on a distinguished road
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?
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 06-08-2008, 08:38 AM
Member
 
Join Date: Jun 2008
Posts: 1
CG2PROJECT is on a distinguished road
Hm, I have a similar project to this one. I need help too!

It will be much appreciated. Thanks in advance.


/Steve
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 06-08-2008, 12:02 PM
Member
 
Join Date: Apr 2008
Posts: 77
Bascotie is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 06-08-2008, 09:31 PM
Member
 
Join Date: Apr 2008
Posts: 77
Bascotie is on a distinguished road
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?

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(); } } }
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 06-10-2008, 09:20 AM
Member
 
Join Date: Apr 2008
Posts: 77
Bascotie is on a distinguished road
Thanks for all your help guys, big thanks to hardw1red and Eranga for their constant help too, if theres anyway i can help the site please let me know.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extra bracket CrazyShells Slam New To Java 5 05-16-2008 07:12 AM
Java assignment xtianah77 New To Java 1 02-18-2008 12:54 AM
for Assignment plz help assamhammad New To Java 1 11-06-2007 09:35 PM
java assignment, need help bad. carlos123 New To Java 1 11-06-2007 05:53 PM
Help with my assignment java toby New To Java 1 08-07-2007 06:59 AM


All times are GMT +3. The time now is 06:32 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org