Results 1 to 3 of 3
  1. #1
    djkazoo2002 is offline Member
    Join Date
    Jul 2014
    Rep Power

    Default 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

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

    my code is

    import java.util.Scanner;

    public class InputGrade

    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;
    char grade =cc.grade;

    int x,y,a;
    final int courseS = 4;
    Scanner input = new Scanner(;

    for(y = 0; y < Sname; ++y)
    teams[y] = new Student();
    System.out.print("Enter student name >> ");
    name = input.nextLine();
    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();
    System.out.print("Enter Grade >> ");
    grade =;

    teams[y].setMember(x, name);
    for(y = 0; y < Sname; ++y)
    System.out.println("\nMembers of team " +
    for(x = 0; x < courseS; ++x)
    System.out.print("yout course is "+teams[y].getMember(x) + "your course ad is" +cc.getcourseID()+"credit hour is" +cc.getcredithours()+"Your grade is "+cc.getgrade());

    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

    public class collegecourse {

    String courseID;
    int credithours;
    char grade;

    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 void setgrade(char g)
    grade = g;

    public char getgrade()

    return grade;

    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

  2. #2
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Rep Power

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


    Seems it's hard to read your entire code. Therefore, please point out where you are strucking.
    (Living @ Virtual World)

  3. #3
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Rep Power

    Default 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.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. I think I'm stuck in an infinite loop...
    By mtliendo in forum New To Java
    Replies: 3
    Last Post: 05-09-2012, 04:04 AM
  2. Stuck in Infinite Loop, Please!
    By jakaldama in forum New To Java
    Replies: 14
    Last Post: 03-27-2012, 06:53 PM
  3. Stuck in a infinite loop
    By Pojahn_M in forum New To Java
    Replies: 8
    Last Post: 08-23-2011, 02:17 AM
  4. Stuck in a bad loop
    By Nadian in forum New To Java
    Replies: 9
    Last Post: 01-19-2011, 06:52 PM
  5. Stuck while loop
    By ile4 in forum New To Java
    Replies: 2
    Last Post: 12-06-2010, 08:17 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts