View Single Post
Old 04-18-2006, 07:33 PM   #1 (permalink)
Bunkertor 7
Banned
 
Bunkertor 7's Avatar
 
Join Date: Nov 2004
Location: Georgia
Posts: 281
+0 Internets
Send a message via AIM to Bunkertor 7
Thumbs up objects and arrays in Java

For my final project in Programing Principles I, we have to make a seemingly simple program that takes in 10 student names through the JOpitonPane window, assign each student 6 random test scores and then sort the student names, a test score (i.e. have the names and the scores correctly switched), and print the test scores.

I did this project last semester for my Intro. to Java class, but I didn't define more than one class (e.g. I didn't use objects). While I thought it would make this process more automated, it's becoming more and more complicated since I want to create an array of objects that will hold 1 string for the name and assign 6 random test scores (which I can do). The problem lies when I try to use this god awful method of swapping elements in arrays that my teacher showed the class how to do (he didn't show us how to swap elements in arrays of objects or how to use the included classes for array searching and sorting).

This code does compile without any errors, but the sorting methods print out way 10 times (instead of one). I'd like to stay away from two dimensional arrays and stick to objects, but I'm willing to try anything at this point.

Code:
import javax.swing.*; import java.util.Arrays; public class Tests { int temp2; public static void main (String[] args) { Student[] srecords = new Student[10]; for(int i=0; i<10; i++) srecords[i] = new Student(); for(int i=0; i=2; j--) for(int k=0; k 0) swap(a, k, k+1); System.out.println("--------------------"+ "\nAfter sorting,"); for(int i=0; i
Bunkertor 7 is offline   Reply With Quote

 
Uberguilds Network