Below is the start of a definition for a Course class. Each Course stores its name, current enrollment, and maximum enrollment. In the class definition, provide a Course constructor and define methods so that the following code will compile:
Course introJava = new Course("Java Programming", 15, 25);
System.out.println("Course currently has " + introJava.getCurrentEnrollment() + " students");
System.out.println("How many students to add?");
Scanner input = new Scanner(System.in);
int moreStudents = input.nextInt();
introJava.addStudents(moreStudents);
System.out.println("Course currently has " + introJava.getCurrentEnrollment() + " students");
if (introJava.overFull()){
System.out.println("too many students!");
}
When the code fragment above is run, the output might look like:Course currently has 15 students How many students to add? 18 Course currently has 33 students too many students!
I started right here with my code:
public class Course
{
private String name;
private int enrollment;
private int max_enrollment;
public course (String nm, int currentEnrollment, int max_ currentEnrollment)
{
name = nm;
Enrollment = currentEnrollment;
max_enrollment = max_ currentEnrollment;
}
public getCurrentEnrollment ()
{
return enrollment;
}
}
Edited by Alexander, 09 December 2010 - 09:06 PM.
(code tags)


Sign In
Create Account


Back to top









