Results 1 to 10 of 10
  1. #1
    chango77745 is offline Member
    Join Date
    Feb 2009
    Posts
    27
    Rep Power
    0

    Default Trying to create gradelist

    Hello all,

    I have been trying to figure out how to write this simple part of the program, but the instructions have me confused. PLEASE help me understand what they are asking for....

    Design a class to represent a list of grades. The class will also have a list of weights for averaging the grades. The two lists should have the same size. The class will manage the two lists and allow a client to obtain an average of the grades using either a standard average or a weighted average.
    Start by writing a constructor for the class. The constructor will take one parameter, the number of grades. It will create two arrays of the given size. Grades will be integers between 0 and 100. Grade weights will be between 0 and 1. The constructor will set each grade to 0 and set all of the weights equal. The sum of the weights will be 1.0.
    This is what I have so far, but I don't want to continue because I know im on the wrong track.

    Java Code:
    public class GradeList {
    	int myTests;
    	int myQuizzes;
    	
    	double weightedQuizzes;
    	double weightedTests;
    	
    	public void GradeList (int numGrades){
    		myTests = 0;
    		myQuizzes = 0;
    		weightedQuizzes =1.0
                              weightedTests = 1.0
                              numGrades -0;
    
    	
    	}
    	
    
    }
    PLEASE HELP!

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default

    The question itself is a bit odd given that the weights assigned to various grades is generally something that is shared between various grade lists (ie they are weighted in the same way). But, putting that aside...

    The important bit to start with is this:

    "The constructor will take one parameter, the number of grades. It will create two arrays of the given size".

    So get rid of myTests and myQuizzes - there is nothing about them in the question - and instead have your class

    (1) declare a couple of instance variables (nicely named) which are arrays. The array that will hold grades should be the correct type to hold integers and the one for weights should be the correct type to hold floating point numbers.

    (2) In your constructor, initialise the two arrays so they have the length given by numGrades.

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default

    Once the constructor has initialised the two arrays it can use a for loop to populate them.

    Do you understand what values should be put into the arrays? (based on the last couple of sentences of the instructions)

  4. #4
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    i cant found the constructor in your code

    have you try?

  5. #5
    chango77745 is offline Member
    Join Date
    Feb 2009
    Posts
    27
    Rep Power
    0

    Default

    pbrockway2, thank you for yor reply. This is getting me on the right track. I don't think that it is correct yet, but I am getting theere. This is what I have so far, I am messing up in the constructor and I am not sure what to do.

    Java Code:
    public class GradeList {
    	int [] grades = new int [101];
    	float [] weights = new float [1];
    	
    	
    	public void GradeList (int numGrades){
    		//This what you mean by initialise the two arrays 
    		//so they have the length given by numGrades 
    		int [] grades = new int [numGrades];
    		
    		
    		
    		
    	
    	}
    	
    
    }

  6. #6
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    there is no reason to initialize your arrays when you declare them. if you are getting an error or exception, let us know what it is. if the behavior is incorrect, explain exactly where in the code it starts misbehaving.
    Last edited by emceenugget; 02-26-2009 at 09:58 PM. Reason: left out a couple words...

  7. #7
    chango77745 is offline Member
    Join Date
    Feb 2009
    Posts
    27
    Rep Power
    0

    Default

    Well, I am trying to
    write a constructor for the class. The constructor will take one parameter, the number of grades. It will create two arrays of the given size. Grades will be integers between 0 and 100. Grade weights will be between 0 and 1. The constructor will set each grade to 0 and set all of the weights equal. The sum of the weights will be 1.0.

    So I wrote this
    Java Code:
    public class GradeList {
    	int [] grades;
    	float [] weights;
    	
    	
    	public void GradeList (int numGrades){ 
    		grades = new int [numGrades];
    		for (int i=1; i<numGrades; i++){
    			grades [i] = 0;
    			weights = 1/numGrades;
    		}
    			
    		
    		
    		
    		
    		
    	
    	}
    	
    
    }
    But I get an error saying cannot convert int to float when trting to set the weights = to 1/numGrades so they can be equal.

  8. #8
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default

    @Chango - I'm a bit reluctant to contribute while the dialog is going on in two places at once. (forums.sun.com/thread.jspa?threadID=5369984&tstart=0)

    Change the "float" to double, read the "nuts and bolts" link from Sun's Tutorial that you were pointed to and change the code so that it declares the arrays but does not initialise them until the constructor is called.

    It's your call - but, at the moment, people are repeating one another in these threads. It would be vastly more productive to pick one thread and point those in the other to it.

  9. #9
    chango77745 is offline Member
    Join Date
    Feb 2009
    Posts
    27
    Rep Power
    0

    Default

    I pick the other thread...it has more information. I am not sure how to close this one.

  10. #10
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default

    People can see the link in #8 and figure out what's going on.

Similar Threads

  1. need to create two methods
    By alims52 in forum New To Java
    Replies: 2
    Last Post: 10-26-2008, 01:35 PM
  2. How to create a GeneralPath
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-25-2008, 11:38 AM
  3. how to create different arrays
    By osval in forum New To Java
    Replies: 2
    Last Post: 08-07-2007, 12:07 AM
  4. Create XML From XSD
    By Jack in forum XML
    Replies: 1
    Last Post: 07-09-2007, 01:56 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
  •