# Thread: Hello, I am stuck with my code. Loop and Array

1. Member
Join Date
Jul 2014
Posts
1
Rep Power
0

## Hello, I am stuck with my code. Loop and Array

Hello, I started to learn Java from last month. I studied array this week. It gets confused me.

I have been tried to solve this homework for all weekends but I can not figure out and I am stuck. if anybody can teach me, that would be help. Thank you so much.

The question is

Write an application that prompts a professor to enter grades for five different
courses each for 10 students. Prompt the professor to enter data for one student at a
time, including student ID and course data for five courses. Use prompts containing
the number of the student whose data is being entered and the course number—for
example,“Enter ID for student #s”, where s is an integer from 1 through 10,
indicating the student, and“Enter course ID #n”, where n is an integer from 1
through 5, indicating the course number. Verify that the professor enters only A, B,
C, D, or F for the grade value for each course. Save the file as InputGrades.java.

I think I have to fix the red parts, Thank you so much/

my code is

import java.util.Scanner;

{
public static void main(String[] args)
{
String name;
final int Sname = 2; //fix to 10
Student [] teams = new Student[Sname];

collegecourse cc = new collegecourse ();

String coursename =cc.courseID;
int credithours =cc.credithours;

int x,y,a;
final int courseS = 4;
Scanner input = new Scanner(System.in);

for(y = 0; y < Sname; ++y)
{
teams[y] = new Student();
System.out.print("Enter student name >> ");
name = input.nextLine();
teams[y].setStudentID(name);
for(x = 0; x < courseS; ++x)
{
System.out.print("Enter Course Number >> ");
name = input.nextLine();
System.out.print("Enter Course Name >> ");
coursename = input.nextLine();
System.out.print("Enter credit hours >> ");
credithours = input.nextInt();

teams[y].setMember(x, name);
}
}
for(y = 0; y < Sname; ++y)
{
System.out.println("\nMembers of team " +
teams[y].getStudentID());
for(x = 0; x < courseS; ++x)
System.out.println();
}

a. Create a CollegeCourse class. The class contains fields for the course ID (for
example,“CIS 210”), credit hours (for example, 3), and a letter grade (for example,
‘A’). Include get and set methods for each field. Create a Student class containing
an ID number and an array of five CollegeCourse objects. Create a get() and set()
method for the Student ID number. Also create a get() method that returns one
of the Student’s CollegeCourses; the method takes an integer argument and
returns the CollegeCourse in that position (0 through 4). Next, create a set()
method that sets the value of one of the Student’s CollegeCourses; the method
takes two arguments—a CollegeCourse and an integer representing the
CollegeCourse’s position (0 through 4). Save the files as CollegeCourse.java
and Student.java.

public class collegecourse {

String courseID;
int credithours;

public void setcourseID(String cid)
{
courseID = cid;
}
public String getcourseID()
{

return courseID;
}
public void setcredithours(int cd)
{
credithours = cd;

}
public int getcredithours()
{

return credithours;
}
{

}
{

}
}

public class Student{
private String studentID;
final private String[]CollegeCourse = new String[4];

public void setStudentID(String name ){
studentID = name;
}
public String getStudentID(){
return studentID;
}

public void setMember(int number, String name)
{
CollegeCourse[number] = name;
}
public String getMember(int number)
{
return CollegeCourse[number];
}

Thank you so much

Hi,

3. Moderator
Join Date
Apr 2009
Posts
13,532
Rep Power
24

## Re: Hello, I am stuck with my code. Loop and Array

When posting code please wrap it in [ code] tags [ /code].
Unformatted code is hard to read.