Hey you guys, I am finishing my last two assignments in my class and I am having trouble because as you will see, the directions are not as they appear. My class is online so I don't have anyone I can rack my brain to or with and did I mention both my teacher and teacher assistants are out of the country lol.....so maybe you guys will be able to help. Here is the assignment:

Create a Parent class called Student. The Student class shall have attributes name:String (a variable name which is of type String), id:int, classList:ArrayList, gradeList:ArrayList and gpa:double.
Student has two child classes BachelorStudent and MasterStudent. Both classes should have the attribute effectiveGPA:double as well as the method calculateGPA() that returns a double and stores it in the effectiveGPA variable.
For the bachelor class, the method should take all the grades in the gradeList arraylist and average them out (Standard grades, A=4, B=3, C=2, D=1, F=0). For the masters class, the method does the same and then multiplies the result by 0.98.

Write a test driver class to create a bachelor student and a master student. Assign 4 grades in their gradelist variable for each - you can either hardcode this or use input from the screen - your choice.

Once done, calculate and print their GPAs along with their Name and ID and designation (Bachelors or Masters student). Also list out any grades for them that are A and F - do this by using the iteration functionality built in to go through each element in the arraylist and check to see if it is A or F, if so, print it.
Also, in output, first print your name, assignment number, and current date in at least two different format. Not hard coded dates, but current day of the day it is executing.

Attack this assignment one small piece at a time.
First - create the classess.
Second - write the methods for the subclasses
Test out the methods by assigning grades and seeing if they work
Third - study the ArrayList structure to see how iteration through it works.
Write a simple iterator through a test arraylist to see if you can seek out a given value.
Read GregorailCalander class in JAVA API, write simple method which prints current date in two different formats.
After you've nailed all this, put all the pieces together.

Have Fun :)

So so far I have created the parent and child classes and now I am stuck on how to code the calculateGPA() method.... I know that some how I will have to convert the letter grades so that it will know what letter equals what number. I have also declared the attributes so tell me if they look right. Thank you in advance for your help!

public class Student
{
                private String string;
    private int id;
    private String[] classList;
    private double gpa;
    private double[] gradeList;
    private double effectiveGPA;

     public double calculateGPA()
    {
     }
}

public class BachelorStudent extends Student
{
}

public class MasterStudent extends Student
{
}

Grade conversion should be easy.
iteration
enumeration
So each enumeration A through F you can assign to to standard scoring levels?
F=0, D=1, C=2, B=3, A=4

And GPA is merely the average.
@sum( 0...N-1) / N

But you need to fill in all your class requirements first, take a pass at writing your code then we can help.

ok so I am going to try to enumerate the grades with the Student class here is what I put:

public class Student
{
private String string;
private int id;
private String[] classList;
private double gpa;
private double[] gradeList;
private double effectiveGPA;

public enum GradeType
{
   A 
   B
   C
   D
   F
}

public static double getGrade(GradeType gt)
{
    double grade = 4;
    if (gt == GradeType.A)
    else if (gt == GradeType.B)
      grade = 3;
    else if(gt == GradeType.C)
       grade = 2;
    else if(gt == GradeType.D)
        grade = 1;
     else if(gt == GradeType.F)
         grade = 0;
  return grade;
}


public double calculateGPA()
{
}
}

If you're going to use an order letter enum...
public enum GradeType { A, B, C, D, F };
then no need for that case statement comparitor!

nGrade = 4 - myGradeType; { 4...0} <--- {0...4}

Just use a simple function to do the conversion!
Keep as integer. Summation as integer. But convert to float for the division for the averaging!

so is this what it should look like so far?

public class Student
{
	private String string;
	private int id;
	private String[] classList;
	private double gpa;
	private double[] gradeList;
	private double effectiveGPA;

	public enum GradeType { A, B, C, D, F };
	
	public double getGrade()
	{
		nGrade = 4 - myGradeType; { 4...0} <--- {0...4}
	}

No, I'm a bit rusty with my Java...

public int getGrade( GradeType myGrade )
{
   return 4 - myGrade;   // { 4...0} <--- {0...4}
}

it's ok, you're helping me a lot more than my teachers lol
I just need someone to help me and break it down step by step so thank you so much for taking the time to help

ok so this is what I have so far and this is the error I am recieving.... any idea?

public class Student
{
	private String string;
	private int id;
	private String[] classList;
	private double gpa;
	private double[] gradeList;
	private double effectiveGPA;
	private double myGradeType;
	private double nGrade;

	public enum GradeType { A, B, C, D, F };

	public double getGrade()
	{
	nGrade = 4 - myGradeType; // { 4...0} <--- {0...4}
	}
}

C:\Users\Ash Ketchum\Documents\New Folder\Student.java:17: missing return statement
}
^
1 error

Tool completed with exit code 1

Of course

public integer getGrade( GradeType myGrade )
{
    return  4 - myGrade; // { 4...0} <--- {0...4}
}
[B]}[/B]

One too many braces!

And you weren't passing in an argument or returning one!

I kept twiddling that post.
here's the entire thing

public integer getGrade( GradeType myGrade )
{
    return  4 - myGrade; // { 4...0} <--- {0...4}
}

Code tags:

[code=JAVA]
paste code here
[/code]

It's impossible to read otherwise.

public class Student
{
    private String string;
    private int id;
    private String[] classList;
    private double gpa;
    private double[] gradeList;
    private double effectiveGPA;
    private double myGradeType;
    private double nGrade;

    public enum GradeType { A, B, C, D, F };

    public double getGrade()
    {
    nGrade = 4 - myGradeType; // { 4...0} <--- {0...4}
    }
}

I had said before you don't need floats (or doubles) until you are FINALLY done and calculating the final GPA.

But you keep using it in the step by step calcuations so fine!

public double getGrade( GradeType myGrade )
{
    return  4.0 - myGrade; // { 4...0} <--- {0...4}
}

Note That I have a return to return the value passed into the function! You don't.
Also you have that dangling brace before the return! It's in the wrong place!

I also pass a 'GradeType' enum into the function for processing.

ok so now the error is this:

C:\Users\Ash Ketchum\Documents\New Folder\Student.java:39: class, interface, or enum expected
}
^
1 error

Tool completed with exit code 1

count your braces!
For every { there is a }.
Print your code off. Write a little number next to each one! Add 1 for each { and -1 for each }

I totally had a bracket at the very very bottom of the page lol....
anyways ok moving on.... so now I have to code the subclasses
since this method is already calculating the average do I just need to call it in the BachelorStudent?
And how would I go about adding the * 0.98 in the MasterStudent?
And yes I am sorry I feel extra lost if I don't put in the floaters and have the time I forget to put them back in and in the correct way but if it really bothers you I can try to leave them out........

You're only retrieving the converted grade. You need to sum the value with result in a bucket, and increment the grade item tally. When done then do your division.

ok so basically you're saying now I need to do the calculateGPA() method right..... I hope so because that's what I did next so for that I did this

public double calculateGPA(double effectiveGPA)
	{

		double grade = 0;

		for (int i = 0; i<gradeList.size(); i++)

		{

		grade+= gradeList.get(i);

		}

		return grade/gradeList.size();

	}

ok so basically you're saying now I need to do the calculateGPA() method right..... I hope so because that's what I did next so for that I did this

public double calculateGPA(double effectiveGPA)
	{

		double grade = 0;

		for (int i = 0; i<gradeList.size(); i++)

		{

		grade+= gradeList.get(i);

		}

		return grade/gradeList.size();

	}

This function is the same as this:

public double calculateGPA()
	{

		double grade = 0;

		for (int i = 0; i<gradeList.size(); i++)

		{

		grade+= gradeList.get(i);

		}

		return grade/gradeList.size();

	}

You pass the variable effectiveGPA , but don't use it, so you might as well not pass it.

Ohh... since my assignment said that the method calculateGPA() should returns a double and store it in the effectiveGPA variable I thought that is why I was doing that....
so would I put that in the () in the return line?

effectiveGPA is a class/global variable. Don't pass it to a function. Copy and paste the ENTIRE program and post it here. Be extra careful to copy the entire thing, including all brackets, and mention all compiling errors.

Read the spec carefully:

Student has two child classes BachelorStudent and MasterStudent. Both classes should have the attribute effectiveGPA:double as well as the method calculateGPA() that returns a double and stores it in the effectiveGPA variable.
For the bachelor class, the method should take all the grades in the gradeList arraylist and average them out (Standard grades, A=4, B=3, C=2, D=1, F=0). For the masters class, the method does the same and then multiplies the result by 0.98.

calculateGPA () takes no arguments. It returns a double. It stores its result in effectiveGPA. You should therefore not have a variable called grade in your function. It should be effectiveGPA .

This should all be in the CHILD classes BachelorStudent and MasterStudent, not the parent class Student. Just make a dummy function in Student.

public double calculateGPA ()
{
     effectiveGPA = 0.0;
     return effectiveGPA;
}

This function will NEVER be executed, but it still should be there in Student. The functions that will be executed will be in MasterStudent and BachelorStudent, which extend Student. If you haven't created MasterStudent and BachelorStudent yet, do so. You should also write some simple constructors now, as well as a very simple driver program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.