472,796 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,796 software developers and data experts.

Help with Java Arrays and methods ASAP Please!!!

First I need to create 2 classes. The first will contain an ID number and an array of 5 course titles. I also have to create a get and a set method for populating the ID. I also must create a method to get a course. It does this by taking an integer and returning the course to that position (0 through 4). Then I must create a set method that sets the value of one of the courses by taking two arguements a name and an integer and returning the name to the position indicated by the integer.

After that I must write an application that prompts the user for grades for 5 different courses: it will prompt for the the id number, then course data for each of 5 courses for that ID number. The user will enter the ID number of the student, then when prompted a number from 1 to 5 indicating which course, and a letter grade for the course.

So far this is what I have:
Expand|Select|Wrap|Line Numbers
  1. // CollegeCourse.java
  2. // Chapter 8, Exercise 5a
  3. // A CollegeCourse has an ID, credits, and a letter grade
  4.  
  5. public class CollegeCourse
  6. {
  7.     private String courseID;
  8.     private int credits; 
  9.     private char grade;
  10.     public String getID()
  11.     {
  12.         return courseID;
  13.     }
  14.     public int getCredits()
  15.     {
  16.         return credits;
  17.     }
  18.     public char getGrade()
  19.     {
  20.         return grade;
  21.     }
  22.     public void setID(String idNum)
  23.     {
  24.  
  25.     }
  26. }
  27.  
  28.  
Expand|Select|Wrap|Line Numbers
  1. // Student.java
  2. // Chapter 8, Exercise 5c
  3. // A Student has an ID, and five CoollegeCourses,
  4.  
  5. public class Student
  6. {
  7.     private int stuID;
  8.     private CollegeCourse[] course = new CollegeCourse[5]; 
  9.  
  10.     public int getID()
  11.     {
  12.         return stuID;
  13.     }
  14.  
  15. *******stuck here***********
  16.     }
  17. }
  18.  
Expand|Select|Wrap|Line Numbers
  1. // InputGrades.java
  2. // Chapter 8, Exercise 5b
  3. // Allows input of 5 grades each for 10 students
  4.  
  5. import javax.swing.*;
  6. public class InputGrades
  7. {
  8.     public static void main(String[] args)
  9.     {
  10. // http://www.brpreiss.com/books/opus5/html/page89.html
  11.         Student[] students = new Student[10]; 
  12.  
  13.         int x, y, z;
  14.         String courseEntry, entry = "", message;
  15.         int idEntry, credits;
  16.         char gradeEntry = ' ';
  17.         boolean isGoodGrade = false;
  18.         char[] grades = {'A', 'B', 'C', 'D', 'F'};
  19.         for(x = 0; x < students.length; ++x)
  20.         {
  21.             Student stu = new Student();
  22.             entry = JOptionPane.showInputDialog(null, "For student #" + (x + 1) + ", enter the student ID");
  23.             idEntry = Integer.parseInt(entry);
  24.             stu.setID(idEntry);
  25. *********stuck here****************
  26.             CollegeCourse temp = new CollegeCourse();
  27.             temp.setID(courseEntry);
  28.             temp.setCredits(credits);
  29.             temp.setGrade(gradeEntry);
  30.             stu.setCourse(temp, y);
  31.         }
  32.         students[x] = stu;
  33.     }
  34.         for(x = 0; x < students.length; ++x)
  35.         {
  36.             message = "Student #" + (x + 1) + " ID #" + students[x].getID();
  37.             for(y = 0; y < 5; ++y)
  38.             {
  39.                 CollegeCourse temp = new CollegeCourse();
  40.                 temp = students[x].getCourse(y);
  41.                 message = message + "\n" + temp.getID() + " " + temp.getCredits() + " credits. Grade is " + temp.getGrade(); 
  42.                 JOptionPane.showMessageDialog(null,message);
  43.             }
  44.             System.exit(0);
  45.         }
  46.     }
  47. }
  48.  
Mar 29 '08 #1
1 3645
pronerd
392 Expert 256MB
So your questions is?
Apr 1 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Radha News | last post by:
Hi, I am looking for reference books/tools/code samples for calling java objects/methods from COM/C++ classes. I am reasonably familiar with JNI. If you have used JNI, please let me know of...
2
by: ratedr1 | last post by:
I am currently trying to label rings (jewelry). They make specialized tags (shaped like a butterfly, barbell, dumbell, etc) for this purpose, the label goes through the ring, and then the ends...
1
by: girish.sh | last post by:
Hi all, I am using shell scripts which needs to call to few Java classes. Can anyone help me with the information on how to call Java classes/methods from KSH shell scripts.
1
by: glenn123 | last post by:
Hi, i am just about out of time to produce a working jukebox which has to perform these functions: to play music files when a track is chosen from a list which when the user presses the change genre...
1
by: jgill | last post by:
Have problems with the recordset…if the value of tempPremium is more than > 10,000 than I get no results after this statement executes: set rsDownPayment =...
24
jeffbroodwar
by: jeffbroodwar | last post by:
Hi everyone, Please help me accomplish the following : 1. how can i copy a file in java then paste it in a desired location 2. how can i run a .jar file run by just double clicking...
1
by: Newbie19 | last post by:
I'm just learning java arrays/arraylists and was wondering what are the best books for learning java arrays/arraylists? I know practice is the best way to learn, but I have a hard time...
0
by: vijay bharath | last post by:
how to take backup of database using java by query itself? please help
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.