Results 1 to 2 of 2
  1. #1
    leiferouis is offline Member
    Join Date
    Jan 2009
    Posts
    31
    Rep Power
    0

    Default 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:
    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
    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.
    The second one: is about GUI. For now, I just need some good resources on GUI.

  2. #2
    leiferouis is offline Member
    Join Date
    Jan 2009
    Posts
    31
    Rep Power
    0

    Default

    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.
    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;
        }
    }
    My biggest problem is with the main class... I don't really understand how the data goes into an actual file.
    Last edited by leiferouis; 02-19-2009 at 06:03 AM.

Similar Threads

  1. Random File Access
    By viper110110 in forum New To Java
    Replies: 11
    Last Post: 11-28-2008, 01:28 AM
  2. Random access to text file
    By lunarbof in forum New To Java
    Replies: 1
    Last Post: 11-05-2008, 09:53 PM
  3. Update a record in Random access file
    By Rgfirefly24 in forum New To Java
    Replies: 2
    Last Post: 04-24-2008, 11:07 PM
  4. Random Access Files concept
    By AralX in forum New To Java
    Replies: 2
    Last Post: 12-25-2007, 08:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •