473,752 Members | 11,124 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 3710
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
5942
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 your experiences and things that I need to watch out. I have used JNI 1.1 and it had several bugs and limitations especially for C++ calling Java. Is the newer version of JNI (version 1.4) any better?
2
2026
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 stick together. What I want to do is type information on these tags rather than write on them, the only problem that I am having is that there is NO template tht I can find anywhere for these labels. Now I have purchased the labels and I have them...
1
5284
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
2289
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 button the list is populated with a list of that genre. I have got the interface done to satisfaction, my problem is that when i press the change genre button nothing happens and when i select a track to play from the list which is setvisible and...
1
1402
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 = applyFilterAndReloadRecordset(rsDownPayment,"min_premium <=" & tempPremium & " and b80_userline = '" & objLogic.userline & "' and profile = '" & objLogic.profile & "'") I was trying to debug the application using response.write statement but get no results if the values of tempPremium...
24
4119
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 on it.... I need to know the answer asap... please reply asap... thanks.
1
1767
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 remembering the little items on arrays/arraylists. Thanks, Newbie
0
1440
by: vijay bharath | last post by:
how to take backup of database using java by query itself? please help
0
9624
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9295
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8295
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6836
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6116
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4738
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4921
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3354
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 we have to send another system
3
2243
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.