I've been having difficulty putting this project together. The idea was to calculate the average grades of students in a classroom with instance variables and scanners. I understand the output and input portion of the assignment but I am struggling the coding below.
public class Averages extends Object
{
// Put any attributes / instance variables here. */
private String name;
// create grade1, grade2, and your Scanner.
// Constructor
public Classroom ()
{
// initialize any attributes that need initial values here */
// initialize your Scanner
return;
}
Then once created I'm supposed to modify my original coding so that it uses instance variables rather than parameter variables. Here is what I originally had:
public double calcAverage (double a, double b)
{
return ((a + b) /2.0);
}
public class Averages extends Object
{
// Put any attributes / instance variables here.
private String name;
// create grade1, grade2, and your Scanner.
// Constructor must have the same name as the class
public Averages()
{
// initialize any attributes that need initial values here `
// initialize your Scanner
}
}
I simply corrected your constructor, the constructor name must match the classname
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.