473,503 Members | 3,740 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with Java Arrays and methods ASAP Please!!!

1 New Member
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 3692
pronerd
392 Recognized Expert Contributor
So your questions is?
Apr 1 '08 #2

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

Similar topics

2
5928
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
2011
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
5277
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
2275
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
1387
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
4097
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
1758
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
1426
by: vijay bharath | last post by:
how to take backup of database using java by query itself? please help
0
7064
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7445
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5559
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4991
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1492
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
369
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.