Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Help with Java code

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with Java code

    I am currently working on a project for a beginners java class. Below is an except of the question:

    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 ge() 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 CollegeCoursesl 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

    b)Write an application that prompts a professor to enter grades for five different courses each for 10 students. Prompt the professor to enter grades for five different couses 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 have successfully completed the (a) part but i am stuck on part (b). Below is the code I have so far:

    public class CollegeCourse
    {
    String courseID;
    int creditHours;
    char grade;

    public void setCourseId(String id) {

    this.courseID = id;

    }

    public String getCourse() {

    return courseID;
    }


    public void setHours(int hours) {

    this.creditHours = hours;
    }

    public int getHours() {

    return creditHours;

    }

    public void setGrade(char grade) {

    this.grade = grade;

    }
    }

    public class Student
    {
    int id;
    CollegeCourse[] cc = new CollegeCourse[5];


    public void setId(int id)
    {

    this.id = id;
    }

    public int getId()
    {

    return id;
    }
    CollegeCourse[] courses;

    public CollegeCourse getCourse(int index) {
    return courses[index];
    }

    public void setCourse(int index, CollegeCourse course) {
    courses[index] = course;
    }
    }
    public class InputGrades
    {
    public static void main(String[] args)
    {
    Student[] students = new Student[10];
    char[] grades = {'A', 'B', 'C', 'D', 'F'};

    for(int x = 0; x < students.length; ++x)
    {
    System.out.println("Enter student Id: ");
    Student stu = new Student();
    stu.setId(Id);

    }
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help with Java code

    i am stuck on part (b)
    Can you explain what part of part (b) you are stuck on?

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with Java code

    the whole of part[b]. I do not understand how to link the Inputgrades class with the two other classes especially.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help with Java code

    Where does it say the classes are to be connected to each other?

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Nov 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with Java code

    it doesn't explicitly say so. But from my understanding I deduced that.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help with Java code

    Try writing the class without it.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 0
    Last Post: May 23rd, 2013, 04:35 PM
  2. Trouble Porting my Java File Reading Code to Android Code
    By Gravity Games in forum Android Development
    Replies: 0
    Last Post: December 6th, 2012, 04:38 PM
  3. Replies: 5
    Last Post: November 14th, 2012, 10:47 AM
  4. Replies: 3
    Last Post: September 3rd, 2012, 11:36 AM
  5. problem in my code java code graph editeur
    By kisokiso in forum Java Theory & Questions
    Replies: 5
    Last Post: January 6th, 2012, 08:36 AM

Tags for this Thread