import java.util.Scanner;
public class Course {
private String courseTitle;
private double feesPerStudent;
private int noOfStudents;
private String[] studentName = new String[100];
private int courseCount;
public Course(String courseTitle, double feesPerStudent) {
this.courseTitle = courseTitle;
this.feesPerStudent = feesPerStudent;
}
public void setCourseTitle(String courseTitle){
this.courseTitle = courseTitle;
}
public String getCourseTitle(){
return courseTitle;
}
public void setFeesPerStudent(double feesPerStudent){
this.feesPerStudent = feesPerStudent;
}
public double getFeesPerStudent(){
return feesPerStudent;
}
public void setNoOfStudents(int noOfStudents){
this.noOfStudents = noOfStudents;
}
public int getNoOfStudents(){
return noOfStudents;
}
public void setStudentName(String[] studentName){
this.studentName = studentName;
}
public String[] getStudentName(){
return studentName;
}
public void setCourseCount(int courseCount){
this.courseCount = courseCount;
}
public int getCourseCount(){
return courseCount;
}
public double calcFeesCollected(){
return getFeesPerStudent() * getNoOfStudents();
}
public void addStudent(String studName){
Scanner scan = new Scanner(System.in);
//System.out.print("Student Name: ");
//studName = scan.next();
studentName[noOfStudents] = studName;
++noOfStudents;
}
public String toString(){
return "\nCourse Title: " + getCourseTitle() + "\nFees Per Student: RM" + getFeesPerStudent() + "0\nNumber Students: " + getNoOfStudents();
}
}
class TestCourse{
public static void main(String[] args){
Course course = new Course("Introduction to Computers", 250);
course.addStudent("Ali Said");
course.addStudent("Wong Ken");
course.addStudent("Peter Lim");
System.out.println(course.toString());
System.out.print("Student Name: ");
for(int i = 0; i < 3; i++){
System.out.print(course.getStudentName());
System.out.printf("\t\t\t\n");
}
System.out.println("Total Fees: " + course.calcFeesCollected());
}
}
since my studentName declared as array with size 100, and i want to get the studentName with array type, how?