Note that there are some explanatory texts on larger screens.

plurals
  1. POReturning object data type from method
    primarykey
    data
    text
    <p>I have some java book and i'm doing exercises. But right now i'm stuck on exercises associated with arrays. i have following exercise:</p> <blockquote> <p>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’). </p> <p>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).</p> </blockquote> <p>I already did data fields and id's and getters from student class. But right now i'm a little confused with this:</p> <blockquote> <p>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).</p> </blockquote> <p>Can anyone point me to the right direction how to resolve this. Because it's array chapter i think it must be resolved doing arrays? Any help would be appreciated.</p> <p>EDIT: ok here is my CollegeCourse Class</p> <p>public class CollegeCourse {</p> <pre><code>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; } </code></pre> <p>}</p> <p>and here is my student class ( im stuck here):</p> <p>public class Student {</p> <pre><code>int id; CollegeCourse[] cc = new CollegeCourse[5]; public void setId(int id) { this.id = id; } public int getId() { return id; } public void setCollegeCourse(CollegeCourse course, int position) { // i'm stuck here } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload