|
-
Newbie to Java programming - Problems with Array assignment
I'm taking an intro to Java course and currently we're taking about arrays. I have the two java files below that I need for the assignment to work, but I'm not sure what to do next with my code.
Here's what the assignment says to do:
Create a 'CollegeCourse class. The class contains fields for the course ID (for example, "History"), credit hours (for example, 3) and a letter grade (for example, 'A'). Include get() and set() accessor 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 would take an integer argument and return the CollegeCourse in the position(0 through 4).
Next, create a set() method that sets the value of one of the student's CollegeCourses; the method would take two arguments -- a CollegeCourse and an integer representing the CollegeCourse's position (o through 4).
-----------------------
//CollegeCourse.java file below:
class CollegeCourse
{
private String courseID;
private int creditHours;
private char letterGrade;
public CollegeCourse(String course, int credits, char grades)
{
courseID = course;
creditHours = credits;
letterGrade = grades;
}
//Set Functions
public void setcourseID(String name)
{
courseID = name;
}
public void setcreditHours(int num)
{
creditHours = num;
}
public void setletterGrade(char letter)
{
letterGrade = letter;
}
//Get Functions
public String getCourseID()
{
return courseID;
}
public int getCreditHours()
{
return creditHours;
}
public char getLetterGrades()
{
return letterGrade;
}
}
==========================
public class Student
{
public static void main(String[] args)
{
showValues(courses[0]);
}
public Student(int ID)
{
idNumber = ID;
courses[0] = new CollegeCourse ("History", 0, 'A');
courses[1] = new CollegeCourse ("Math", 0, 'A');
courses[2] = new CollegeCourse ("English", 0, 'A');
courses[3] = new CollegeCourse ("Music", 0, 'A');
courses[4] = new CollegeCourse ("Science", 0, 'A');
}
public int getCourse()
{
return idNumber;
}
public static void showValues(Show c)
{
System.out.println c.getCourse();
}
}
Thanks
Similar Threads
-
Replies: 1
Last Post: 05-13-2005, 06:46 AM
-
By Rob Abbe in forum Talk to the Editors
Replies: 44
Last Post: 01-13-2003, 02:57 PM
-
Replies: 2
Last Post: 12-13-2001, 09:55 PM
-
By Novosoft in forum web.announcements
Replies: 0
Last Post: 02-14-2001, 03:50 AM
-
By Muhammad Alam in forum Java
Replies: 1
Last Post: 03-24-2000, 09:19 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks