import java.util.*;
public class course
{
 static Scanner sc=new Scanner(System.in);
 public static void main(String[]args)
 {
 	 String name,students,addStudent;
 	 int numberOfStudents;
 	 String courseName,getName,getStudents;
 	 int getnumberOfStudents;
 	 
 	
 	Course course1=new Course("C++");
 	Course course2=new Course("Java");
 	
 	course1.addStudent("Peter");
 	course1.addStudent("Brian");
 	course1.addStudent("Anne");
 	
 	course2.addStudent("Peter");
 	course1.addStudent("Steve");
 	
 	System.out.println("Num of student in course1:"+course1.getnumberOfStudents());
 	
 	String[]students=course1.getStudents();
    for (int i = 0; i < course1.getNumberOfStudents(); i++)
	

 	System.out.println("Num of student in course2:"+course2.getnumberOfStudents());
 	
 	String[]students=course2.getStudents();
    for (int i = 0; i < course2.getNumberOfStudents(); i++)
	

 }
}
what is the problem it does not generate the output the numOfStudents who take c++ n JAVA.please explain to me. i am not good in array...

Recommended Answers

All 6 Replies

import java.util.*;
public class course
{
 static Scanner sc=new Scanner(System.in);
 public static void main(String[]args)
 {
 	 String name,students,addStudent;
 	 int numberOfStudents;
 	 String courseName,getName,getStudents;
 	 int getnumberOfStudents;
 	 
 	
 	Course course1=new Course("C++");
 	Course course2=new Course("Java");
 	
 	course1.addStudent("Peter");
 	course1.addStudent("Brian");
 	course1.addStudent("Anne");
 	
 	course2.addStudent("Peter");
 	course1.addStudent("Steve");
 	
 	System.out.println("Num of student in course1:"+course1.getnumberOfStudents());
 	
 	String[]students=course1.getStudents();
    for (int i = 0; i < course1.getNumberOfStudents(); i++)
	

 	System.out.println("Num of student in course2:"+course2.getnumberOfStudents());
 	
 	String[]students=course2.getStudents();
    for (int i = 0; i < course2.getNumberOfStudents(); i++)
	

 }
}
what is the problem it does not generate the output the numOfStudents who take c++ n JAVA.please explain to me. i am not good in array...

I dont understand ur code but from what I understood, the problem COULD be here.

System.out.println("Num of student in course1:"+course1.getnumberOfStudents());

From the for loop, i understand that the method name is getNumberOfStudents. with a capital N. however, the same mistake is there in the second one also, meanin course2.getnumberOf....

if its not the problem, u might wanna post the code for the class Course.

C:\Documents and Settings\Administrator\Desktop\course\src\course.java:37: illegal start of expression
 }
 ^
C:\Documents and Settings\Administrator\Desktop\course\src\course.java:38: reached end of file while parsing
}2 errors

Process completed.

this is the error and i cant understand.
already change the getNumberOfStudents to getnum....
but same error generated

start quote:

C:\Documents and Settings\Administrator\Desktop\course\src\course.java:37: illegal start of expression
 }
 ^
C:\Documents and Settings\Administrator\Desktop\course\src\course.java:38: reached end of file while parsing
}2 errors

Process completed.

this is the error and i cant understand.
already change the getNumberOfStudents to getnum....
but same error generated

try changing getnumber to getNumber, and please post the Course class.
ps: the code u posted doesnt have a 37th line.... just wonderin aloud. the actual program in ur pc might have. so..

and really this code is going over the head. can u explain ur requirements. I am also not an expert but i think i can help with something like this.

actually the Question is like this:
create 2 courses which are c++ n java
then, add students to c++ n java
print out the num of students taking c++ and the list of their names
print out the num of students taking java and the list of their names

this is the requirement for the question

try changing getnumber to getNumber, and please post the Course class.
ps: the code u posted doesnt have a 37th line.... just wonderin aloud. the actual program in ur pc might have. so..

it is refering to the two closing brackets
for the public class course
and for the public static void main(String[]args)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.