Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m getting errors saying my contructor is undefinied and that a method is miss

ID: 3666395 • Letter: I

Question

I'm getting errors saying my contructor is undefinied and that a method is missing a return type but I have a return. How do I fix this? (Problem number 7.3 on java software solutions 8th edition)

Course Class:

import java.util.ArrayList;

import java.util.List;

public class Course
{

private String name;

private List<Student> students;

public Course(String name)
{
this.name = name;

students = new ArrayList<Student>();
}

public void addStudent(Student stud)
{
students.add(stud);
}

public double average()
{ double avg = 0.0;
int size = Course.size();
for(int x = 0; x < size; x++)
{
avg += course.get(x).getAverage();
}
avg = avg/size;
return avg;
}

public void roll()
{
System.out.println("Course: " + name);
System.out.println("Students:");

}
}

--------------------------------------------

import java.util.*;
public class CourseDriver {

public static void main(String[] args) {
Course course = new Course("CS");
course.addStudent(new Student("Gates", "Bill"));
course.addStudent(new Student("Jobs", "Steve"));
course.addStudent(new Student("Dell", "Michael"));
course.roll();
}
}

---------------------------------------------------------------------------------------------------

public class Student
{
private String firstName, lastName;
private Address homeAddress, schoolAddress;
private int score1, score2, score3; //instance variables for 3 test scores of student
private int test1, test2, test3;
private final int t1 = 1;
private final int t2 = 2;
private final int t3 = 3;
  
public Student()//default constructor
{
score1 = 0;
score2 = 0;
score3 = 0;
//assumed to be initially zero
}
  
  
public Student (String first, String last, Address home, Address school, int test1, int test2, int test3)
{
firstName = first;
lastName = last;
homeAddress = home;
schoolAddress = school;
score1 = test1; //parameters for test scores
score2 = test2;
score3 = test3;
}
public String getLastName()
{
return lastName;
}
public String getFirstName()
{
return firstName;
}

public void setTestScore(int test, int score)
{
switch(test)
{
case t1:
score1 = score;
break;
case t2:
score2 = score;
break;
case t3:
score3 = score;
break;
default:
}
}
public int getTestScore(int test)
{
switch(test)
{
case t1:
return score1;
//break;
case t2:
return score2;
//break;
case t3:
return score3;
//break;
default:
}
return 0;
}
public double average()
{
double avg = (score1 + score2 + score3) / 3.0;
return avg;
}


public String toString()
{
String result;

result = firstName + " " + lastName + " ";

result += "Home Address: " + homeAddress + " ";

result += "School Address: " + schoolAddress;
  
result += " Three test scores: Test 1: " + getTestScore(1) + " Test2: " + getTestScore(2) + " Test 3: " + getTestScore(3);
result += " Average: " + average();
return result;
}
}

Explanation / Answer

import java.util.ArrayList;
import java.util.List;
import java.util.*;

class Course
{
   private String name;
  
   private List<Student> students;
  
   public Course(String name)
   {
       this.name = name;
       students = new ArrayList<Student>();
   }
   public void addStudent(Student stud)
   {
       students.add(stud);
   }
   public double average()
   {
       double avg = 0.0;
       int size = Course.size();
       for(int x = 0; x < size; x++)
       {
           avg += Course.get(x).getAverage();
       }
       avg = avg/size;
       return avg;
   }
   public void roll()
   {
       System.out.println("Course: " + name);
       System.out.println("Students:");
   }
}

class Student
{
   private String firstName, lastName;
   private Address homeAddress, schoolAddress;
   private int score1, score2, score3; //instance variables for 3 test scores of student
   private int test1, test2, test3;
   private final int t1 = 1;
   private final int t2 = 2;
   private final int t3 = 3;
  
   public Student()//default constructor
   {
       score1 = 0;
       score2 = 0;
       score3 = 0;
       //assumed to be initially zero
   }
  
  
   public Student (String first, String last, Address home, Address school, int test1, int test2, int test3)
   {
       firstName = first;
       lastName = last;
       homeAddress = home;
       schoolAddress = school;
       score1 = test1; //parameters for test scores
       score2 = test2;
       score3 = test3;
}
   public String getLastName()
   {  
       return lastName;
   }
   public String getFirstName()
   {
       return firstName;
   }
   public void setTestScore(int test, int score)  
   {
       switch(test)
       {
           case t1:
               score1 = score;
               break;
           case t2:
               score2 = score;
               break;
           case t3:
               score3 = score;
               break;
           default:
       }
   }
   public int getTestScore(int test)
   {
       switch(test)
       {
           case t1:
               return score1;
               //break;
           case t2:
               return score2;
               //break;
           case t3:
               return score3;
               //break;
           default:
       }
       return 0;
   }
   public double average()
   {
       double avg = (score1 + score2 + score3) / 3.0;
       return avg;
   }

   public String toString()
   {
String result;
       result = firstName + " " + lastName + " ";
       result += "Home Address: " + homeAddress + " ";
       result += "School Address: " + schoolAddress;
  
       result += " Three test scores: Test 1: " + getTestScore(1) + " Test2: " + getTestScore(2) + " Test 3: " + getTestScore(3);
       result += " Average: " + average();
       return result;
   }
}

public class CourseDriver
{
   public static void main(String[] args)
   {
       Course Course = new Course("CS");
       Course.addStudent(new Student("Gates", "Bill"));
       Course.addStudent(new Student("Jobs", "Steve"));
       Course.addStudent(new Student("Dell", "Michael"));
       Course.roll();
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote