Results 1 to 5 of 5
  1. #1
    GlobalJedi is offline Member
    Join Date
    Oct 2014
    Posts
    2
    Rep Power
    0

    Default Need Help With Java Assignment

    Hey guys,

    I am fairly new to Java and approaching the end of my first java course. The assignment I am working on is basically creating a class GradeBook , to have the students first name, last name, ID number, and Five test grades. From this class create an instance of it. Now, in an effort to preserve the work of the student from year to year, we need to create an immutable class called LastYearsGrades. From that class create an instance for MathI + the previous year. For example, MathI2010 would be the class used for last year's math grades. Fill that grade book with the grades from the first instance of the grade book class that you created.

    I am not trying to get spoon fed the code but I do truly need some help. This is what I have so far:

    Java Code:
    public class Assignment_9_1{
     
    public static void main(String a[]){
     
    Scanner input = new Scanner(System.in);
            String [] FirstName = new String [50];
            String [] LastName = new String [50];
            String [] ID = new String [50];
            int [] TestOne = new int[50];
            int [] TestTwo = new int[50];
            int [] TestThree = new int[50];
            int [] TestFour = new int[50];
            int [] TestFive = new int[50];
    
           for (int i = 0; i < 50; i++){
                System.out.println("Enter students First name: ");
                String studentFirstName = input.nextLine();
    
                FirstName [i] = studentFirstName;
                
                System.out.println("Enter students Last name: ");
                String studentLastName = input.nextLine();
    
                LastName [i] = studentLastName;
                
                System.out.println("Enter students ID Number: ");
                String studentID= input.nextLine();
    
                ID [i] = studentID;
                        
                System.out.println("Enter students first test grade : ");
                int studentGrade= input.nextInt();
    
                TestOne [i] = studentGrade;
                
                System.out.println("Enter students second test grade : ");
                int studentGrade1= input.nextInt();
    
                TestTwo[i] = studentGrade1;
                
                System.out.println("Enter students third test grade : ");
                int studentGrade2= input.nextInt();
    
                TestThree[i] = studentGrade2;
                
                System.out.println("Enter students fourth test grade : ");
                int studentGrade3= input.nextInt();
    
                TestFour[i] = studentGrade3;
                
                System.out.println("Enter students fifth test grade : ");
                int studentGrade4= input.nextInt();
    
                TestFive[i] = studentGrade4;


    I then have a few print methods to display all of the input. Any pointers on how I can set this up so that I can maybe keep the info stored, and add more students?

    Thanks!
    Last edited by JosAH; 12-09-2014 at 09:43 AM. Reason: added [code] ... [/code] tags

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Need Help With Java Assignment

    "creating a class GradeBook , to have the students first name, last name, ID number, and Five test grades"

    Start there.
    Currently you have no GradeBook class, so there's no point attempting anything after this point.
    That class has:
    "first name, last name, ID number, and Five test grades"
    So two Strings, an int and an int[5].
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    GlobalJedi is offline Member
    Join Date
    Oct 2014
    Posts
    2
    Rep Power
    0

    Default Re: Need Help With Java Assignment

    @Tolls, thanks for pointing out the obvious that I couldn't even see, sad on my part. Anyways, i made my grade book class as follows:

    Java Code:
    public class GradeBook {
    
    	String FirstName;
    	String LastName;
    	int IdNum;
    	int Tests [5];
    
    	public String getFirstName() {
    		return FirstName;
    	}
    
    	public String getLastName() {
    		return LastName;
    	}
    
    	public int getIdNum() {
    		return IdNum;
    	}
    
    	public int getTests() {
    		returnTests;
    	}
    }
    Now I'm not sure if I even want to be getting this input right now, What the assignment is looking to have is an "immutable class" called LastYearGrades where you combine this year's grades along with preivous years. The whole purpose is that the grades from the previous year get imported and preserve. My teacher said i need to be looking at data encapsulation to do this.

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Need Help With Java Assignment

    Here's a hint. For your immutable class make your variables private and use only getters to access them. Don't allow setters. And if you return an object or array reference, return a copy of the object or array and not the real thing. Otherwise, another class can change the values.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Need Help With Java Assignment

    And that immutable class will have a constructor that accepts a GradeBook and uses the values held there to populate its values.

    Note that Java naming standards say your class attributes should start with a lower case letter.
    In addition, they should be private and you should provide a setXXX method for each of them, though arguably the ID shouldn't change and possibly the names.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Java Assignment
    By roladejo in forum Advanced Java
    Replies: 2
    Last Post: 05-09-2013, 01:25 AM
  2. Need help with a java assignment
    By Proera92 in forum New To Java
    Replies: 6
    Last Post: 01-07-2013, 04:04 PM
  3. Help with java assignment
    By jason3460 in forum New To Java
    Replies: 6
    Last Post: 12-04-2012, 11:47 PM
  4. Java Assignment help?
    By smith999 in forum New To Java
    Replies: 1
    Last Post: 11-24-2012, 01:25 AM
  5. Help with my assignment java
    By toby in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06: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
  •