Results 1 to 2 of 2
Thread: random file access and GUI
- 02-18-2009, 11:23 PM #1
Member
- Join Date
- Jan 2009
- Posts
- 31
- Rep Power
- 0
random file access and GUI
I have two assignments i must complete in two days which I don't know much about.
The first one:
For this assignment, I am having trouble figuring out how to tackle the assignment. I am thinking of doing arrays but I don't know how to random file access with arrays. Also I'm not sure whether I should read the file under each function.Write a program which allows the user to manage a random file of 15 maximum students who are taking this on-line course. Each student can have 6 different marks assigned to them: Thinking, Applications, Communications, Thinking, Exam, and Final Mark. Use the percentage breakdowns for this course to determine the final mark. Because students in on-line courses are at different points in the course, random access has been choosen. From a menu give the user the following options:
* enter initial class list of all student names
* add/delete a student
* enter a mark (Thinking, Applicatinos, Communications, Knowledge or Exam)
* modify a mark (Thinking, Applicatinos, Communications, Knowledge or Exam)
* calculate final mark
The second one: is about GUI. For now, I just need some good resources on GUI.
- 02-19-2009, 04:21 AM #2
Member
- Join Date
- Jan 2009
- Posts
- 31
- Rep Power
- 0
Here is my current class for the file accessing. This is only to contain methods of random file access, the actual menu, inputting and stuff is in a separate class.
My biggest problem is with the main class... I don't really understand how the data goes into an actual file.Java Code:// A class which defines a student record - StudentRecord import java.io.*; public class StudentRecord { protected int studentnum; protected String name; protected int thinking, application, communication, knowledge, exam; protected double finalmark; protected static final int RECORD_SIZE = 57; // Constructor to read record from file public StudentRecord (RandomAccessFile input) throws IOException { //read student number studentnum = input.readInt(); // read student name byte[] nameBytes = new byte [30]; input.readFully (nameBytes); name = new String (nameBytes, 0); //read marks thinking = input.readInt(); application = input.readInt(); communication = input.readInt(); knowledge = input.readInt(); exam = input.readInt(); finalmakr = input.readDouble(); } // Constructor uses data from keyboard public StudentRecord (int studentnum, String name, int thinking, int application, int communication, int knowledge, int exam, double finalmark) { this.studentnum = studentnum; this.name = name; this.thinking = thinking; this.application = application; this.communication = communication; this.knowledge = knowledge; this.exam = exam; this.finalmark = finalmark; } // Method to get student number public int getStudentnumber () { return studentnum; } // Method to get student name public String getName () { return name; } // Method to get thinking public String getThinking () { return thinking; } // Method to get application public double getApplication () { return application; } //Method to get communication public int getCommunication () { return communication; } // Method to get knowledge public int getknowledge () { return knowledge; } //Method to get exam public int getExam () { return exam; } // Method to get final mark public int getFinalmark () { return finalmark; } // Method to get record size. public static int recordSize () { return RECORD_SIZE; } // Method to write a record to file. public void write (RandomAccessFile output) throws IOException { //output student number output.writeInt(studentnum); //output student name name=fillspace(name,30); byte[] nameBytes = new byte [30]; name.getBytes(0, name.length (), nameBytes, 0); output.write(nameBytes); //output marks output.writeInt(thinking); output.writeInt(application); output.writeInt(knowledge); output.writeInt(communication); output.writeInt(exam); output.writeDouble(finalmark); } // Method to fill extra string room with spaces public static String fillspace (String word, int lengthtofill) { int stringlength, x; stringlength = word.length (); for (x = stringlength; x <= lengthtofill-1 ; x++) { word = word + " "; } return word; } }Last edited by leiferouis; 02-19-2009 at 05:03 AM.
Similar Threads
-
Random File Access
By viper110110 in forum New To JavaReplies: 11Last Post: 11-28-2008, 12:28 AM -
Random access to text file
By lunarbof in forum New To JavaReplies: 1Last Post: 11-05-2008, 08:53 PM -
Update a record in Random access file
By Rgfirefly24 in forum New To JavaReplies: 2Last Post: 04-24-2008, 10:07 PM -
Random Access Files concept
By AralX in forum New To JavaReplies: 2Last Post: 12-25-2007, 07:04 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks