Results 1 to 10 of 10
  1. #1
    Bascotie is offline Member
    Join Date
    Apr 2008
    Posts
    88
    Rep Power
    0

    Default [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

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    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:
    Java 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":
    Java 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.

  3. #3
    Bascotie is offline Member
    Join Date
    Apr 2008
    Posts
    88
    Rep Power
    0

    Default

    Thank you I'll try to finish the student class and ask you guys if it looks correct! :)

  4. #4
    Bascotie is offline Member
    Join Date
    Apr 2008
    Posts
    88
    Rep Power
    0

    Default

    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;
    		}
    		
    
    }

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    This statement:
    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?

  6. #6
    Bascotie is offline Member
    Join Date
    Apr 2008
    Posts
    88
    Rep Power
    0

    Default

    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?

  7. #7
    CG2PROJECT is offline Member
    Join Date
    Jun 2008
    Posts
    1
    Rep Power
    0

    Default

    Hm, I have a similar project to this one. I need help too!

    It will be much appreciated. Thanks in advance.


    /Steve

  8. #8
    Bascotie is offline Member
    Join Date
    Apr 2008
    Posts
    88
    Rep Power
    0

    Default

    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.

  9. #9
    Bascotie is offline Member
    Join Date
    Apr 2008
    Posts
    88
    Rep Power
    0

    Default

    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();
    		}
    		
    	}
    	
    	
    }

  10. #10
    Bascotie is offline Member
    Join Date
    Apr 2008
    Posts
    88
    Rep Power
    0

    Default

    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.

Similar Threads

  1. Extra bracket
    By CrazyShells Slam in forum New To Java
    Replies: 5
    Last Post: 05-16-2008, 06:12 AM
  2. Java assignment
    By xtianah77 in forum New To Java
    Replies: 1
    Last Post: 02-17-2008, 11:54 PM
  3. for Assignment plz help
    By assamhammad in forum New To Java
    Replies: 1
    Last Post: 11-06-2007, 08:35 PM
  4. java assignment, need help bad.
    By carlos123 in forum New To Java
    Replies: 1
    Last Post: 11-06-2007, 04:53 PM
  5. Help with my assignment java
    By toby in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •