Question:
java programming help with constructers?
anonymous
2010-06-01 04:50:07 UTC
Write a OOP program for your Computer Science teacher that can be used to calculate final grades. The teacher uses the following grade items:
1. five quizzes, each graded out of 10 points
2. a midterm exam graded out of 100 points
3. a final exam, graded out of 100 points

The defining class should contain a constructor with parameters for student’s name, test marks, midterm mark and final exam.

The defining class will have one method to calculate a student’s numeric grade and their final letter grade. Grade items will be weighted as follows:

1. final exam counts for 25% of the final mark
2. midterm counts for 25%
3. five quizzes together count for a total of 50%.

The method should output both the calculated, numeric grade and the final letter grade.

Write a tester class to test your application. Use the constructor to create five students and initialize the instance variables for each student. Invoke the method to calculate the numeric grade and final letter grade for each student. Output each student’s name and show their numeric grade and letter grade.
______________________________________…

now my question is im just not sure where to get started with it, im really having trouble with this course and have just got the constructor concept last night after watch youtube videos lol

this is all i got, its really nothing and im already confused about what i wrote.
______________
public class grades{

}

class gradesTester{
private String studentName;
public void setName(String name){
studentName=name;
}
public String getName(){
return studentName;
}
}
Three answers:
anonymous
2010-06-01 05:29:24 UTC
Let me just give you an example using which you can complete your task.



First of all you need a Class...Lets call our Class as GradeFinder



inside a Class you have few things like variables, methods.



So now we need to have variables which stores Student name, and various marks



And of course we need to have a method which calculates the overall mark



Class GradeFinder

{

// Here are Variables

public String Student_name;

public int mark1;

public int mark2;



// We need a constructor which will initialize values

// to variables when object is created for this class

// Constructor name is same as class name



public GradeFinder(String name,int m1,int m2)

{

// Whatever is in (name,m1,m2) is assigned to

//Student_name,mark1,mark2 variables

// of our Class

Student_name=name;

mark1=m1;

mark2=m2;

}



// Then of course we need a method which returns the overall mark

// using mark1 and mark2



public int calculateOverallMark()

{

// here You have to do the required calculation.

//Here is how i calculate my overall mark.



int overall =(mark1+mark2)/2;

return overall;



//return will return overall's value whenever this method is used

}

}



Class MyMainClass()

{

public static void main(String args[])

{

//Here is where the program starts to execute

//bCoz this is main function



//Now create an object for the class "GradeFinder"



GradeFinder obj1=new GradeFinder("Tommy",70,70);



//While creating object named "obj1", initialization of

//variables is also done using the constructor that was created before



//now just use the object created and call the method to find overall mark



int returned_overall= obj1.calculateOverallMark();



//method returns overall mark

//which gets stored inside "returned_overall" variable



System.out.println("Hi"+obj1.Student_name+ "You Scored"+returned_overall);



//Thats all...You do what you have to do...

}

}



I dont know how much my answer was helpful, but here is what i would recommend

to anyone who needs good intro to programming



Watch this in youtube..its by a professor in stanford university..

http://www.youtube.com/watch?v=KkMDCCdjyW8&feature=related
AnalProgrammer
2010-06-01 05:04:58 UTC
The clues here are in the description.

This is a Student class.

So

public class Student {

public Student() { // This is a constructor!! Same name as the class.

//The constructor sits INSIDE the class. There can be more than one constructor.

}

}



You know that you want 3 different exams. But the first is actually 5 quizzes.

So the first should be an int array with 5 ooccurrences

The other two are just ints.

Those are the variables sorted. Now lets look again at the constructor.



"The defining class should contain a constructor with parameters for student’s name, test marks, midterm mark and final exam."



So the constructor should be

public Student(String name, int[] testMarks, int midTerm, int finalExam)



That should get you started. But please re-read the problem.



Have fun.
hinnant
2016-12-04 15:52:24 UTC
first of all, it incredibly is Java, not JAVA. Java isn't an acronym of something, like consumer-friendly or COBOL. it is incredibly undemanding. particularly much any type can income from constructors. How approximately this: type MyCoolClass { String call; int fee; public MyCoolClass( String theName, int theValue ) { call = theName; fee = theValue; } public String getName() { return call; } public int getValue() { return fee; } } You get the assumption. HTH


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...