Jump to content

Please Help

- - - - -

  • Please log in to reply
3 replies to this topic

#1
lina

lina

    Learning Programmer

  • Members
  • PipPipPip
  • 34 posts
Need help on finishing this program:
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)


#2
lina

lina

    Learning Programmer

  • Members
  • PipPipPip
  • 34 posts
Can anyone help please?

#3
so1i

so1i

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 312 posts
What exactly are the problems you are having?

I haven't tried your code or anything, but I did just spot that your constructor has no capital 'C' on course. I'm not sure if that's just a typo here, but if it isn't and the code isn't running. That might be a reason.
My Company - My Homepage - My Twitter - My Google+ - My LinkedIn

"Things don’t have to change the world to be important.” - Steve Jobs

#4
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
you need the following two methods
public void addStudents(int moreStudents){
    enrollment += moreStudents;
}

public boolean overFull(){
    return enrollment > max_enrollment;
}





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users