Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Need help with Java Assignment (code partially complete)

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help with Java Assignment (code partially complete)

    Imagine that you were required to write a Java program which will store, manipulate, and print student registration information.

    As part of the solution, identify the following classes:
    (a) Student
    (b) Admissions.

    The class Student has the following fields – Name, Address, Id number, Courses, and Date, where:
    (a) Name is a user defined class comprising of at minimum first name and last name.
    (b) Address is a user defined class comprising of fields - street, city, state, and zip code.
    (c) Date is a predefined class in the java.util package
    (d) Id number uniquely identifies a student.
    (e) Courses is a user defined class that can store at most five courses for which a student may register for. A student after registering should be able to add/drop course(s).


    The class Admissions stores and manipulates the student information (student record). Because the list of students may grow dynamically, it is best to use a dynamic data structure such as the ArrayList to store the information. This class should do the following, among other possible activities:
    (a) Add student to the list
    (b) Remove student from the list.

    You are to provide a test class that coordinates the activities of the classes outlined above, by:
    • Creating student objects and adding them to the database of the Admissions object
    • Removing a student from the database
    • Change a student’s last name
    • Displaying list of currently registered students
    • Displaying list of all students that were dropped from the course

    The output must be formatted as follows, and must be placed in a scrollable pane:

    CURRENTLY ENROLLED
    Id number: 123456
    Name: Williams, John
    Address: 2525 Hartsfield Road
    Tallahassee, FL 33319
    Date: September 5, 2010
    Courses: COP3337 MAC2311 ENC1102 :
    :
    :

    STUDENT WHO WERE DROPPED
    Id number: 56789-0
    Name: Roberts, Kay-Anne
    Date: September 5, 2010

    Code:

    import java.util.ArrayList;
     
    public class Admissions
    {
        ArrayList <Student>list; // The  list
     
       // Required for searching
        int index; 		// Position where record was found
        boolean found;	// Whether or not record was found
        Student student;// Whose record was found
     
        Admissions()
        {
            list = new ArrayList<>();
        }
        void add(Student o)
        {
            // Complete method
        }
        boolean empty()
        {
            // Complete method
        }
        int size()
        {
            return list.size();
        }
        Student remove(int i)
        {
            // Complete method
        }
        ArrayList getList()
        {
            return list;
        }
        int getIndex()
        {
            // Complete method
       }
       Student getStudent()
       {
            return student;
       }
       boolean inList()
       {
            // Complete method
       }
       void search (String id) // Search list depending on the id
        {
            found = false; // Determines if item in list
            index = 0;     // Required for index
            int length = list.size();
     
            while ( index < length && !found) // Yet others may prefer th for loop
            {
                student = list.get(index);
                if (student.getId().compareTo(id) == 0)
                      found = true;
                    else
                       index++;
            }
        }
    }

    admissions Class
     
    import java.util.ArrayList;
     
    public class Courses
    {
    	static final int MAX_COURSES = 5;
    	ArrayList <String> crses;
     
        public Courses()
        {
            crses = new ArrayList<String>();
        }
     
        boolean add(String s)
        {
        	if (crses.size() >= MAX_COURSES)
        		return false;
        	crses.add(s);
        	return true;
        }
     
        boolean drop(String crse)
     	{
    		// Complete method
     	}
     
        ArrayList getCourses()
        {
        	return crses;
        }
    }

    test class:
     
     
    import java.util.ArrayList;
    import javax.swing.JOptionPane;
    import javax.swing.JTextArea;
    import javax.swing.JScrollPane;
     
    class StudentAdmissions
    {
        public static void main(String arg[])
        {
            Admissions db = new Admissions();
     
            String menu = "1. Add student\n2. Add courses\n3. Drop course\n4. Drop student\n5. Display\n6. Modify name\n7. Exit";
            boolean more = true;
     
            while(more)
            {
                int i = GetData.getInt(menu);
                switch(i)
                {
                    case 1: // Register new student
    					// Create name object
    					String first = GetData.getWord("Enter first name");
                        String last = GetData.getWord("Enter last name");
                        Name n = new Name(first, last);
     
    					// Create address object
                        String street = GetData.getWord("Enter street");
                        String city = GetData.getWord("Enter city");
                        String state = GetData.getWord("Enter state");
                        String zip = GetData.getWord("Enter zip");
                        Address addr = new Address(street, city, state, zip);
     
    					// Get student id
                        String id =  GetData.getWord("Enter id number");
     
                         // Create Course object
                        Courses crse = new Courses();
                        int option =  GetData.getInt("Ready to add courses?\n1. Yes\n2. No");
                        if(option == 1)
                        	addCourse(crse);
     
                        // Create student object
                        Student s = new Student(n, addr, id, crse);
     
                       // Add student object to the database
                        db.add(s);
     
                    break;
                    case 2: //Existing student
                        int enter = GetData.getInt("Want to add course?\n1. Yes\n2. No");
     
                    break;
                    case 3: // Existing student
                        int drop = GetData.getInt("Want to drop a course?\n1. Yes\n2. No");
     
                    break;
                    case 4: // Existing student
                        int drp = GetData.getInt("Want to drop a student?\n1. Yes\n2. No");
     
                    break;
                    case 5: // Display information - current OR dropped
    					int displ = GetData.getInt("Show\n1. Current student\n2. Dropped students");
                    break;
                    case 6: // Modify student's record
     
                    break;
                    case 7: // End process
                        more = false;
                    break;
                    default:
    					// Do nothing
                    break;
                }
            }
        }
        static void addCourse(Courses crse)
        {
              boolean addAnotherCourse = true;
              while(addAnotherCourse)
              {
                    int enter = GetData.getInt("Do you want to add course?\n1. Yes\n2. No");
                    switch(enter)
                    {
                        case 1:
                              String course = GetData.getWord("Enter name of course");
                              if (!(crse.add(course)))
                              {
                                  display("Can't add any more course", "Cousre Limit Reached", JOptionPane.WARNING_MESSAGE);
                                  addAnotherCourse = false;
                              }
                       break;
                       case 2:
                           addAnotherCourse = false;
                       break;
                       default:
     
                       break;
                   }
              }
        }
         static void display(String msg, String title, int type)
        {
            JOptionPane.showMessageDialog(null, msg,title, type );
        }
    }


    --- Update ---

    need help completing the methods


  2. #2
    Junior Member
    Join Date
    Sep 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with Java Assignment (code partially complete)

    which code is the one you did

  3. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with Java Assignment (code partially complete)

    I just need help figuring out the incompleted methods, especially the test class

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Need help with Java Assignment (code partially complete)

    Quote Originally Posted by forgiveme502 View Post
    I just need help figuring out the incompleted methods, especially the test class
    What are you stuck on? (Take this one problem at a time)
    Be specific in where you are stuck, things like "I am stuck" or "I need help" does not explain what the underlying problem is.

Similar Threads

  1. [SOLVED] I dont know how to complete this code?
    By jwb4291 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 8th, 2017, 11:11 PM
  2. [SOLVED] Code Complete?
    By remedys in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 15th, 2013, 07:15 AM
  3. my assignment..not able to complete it...please help...
    By d4divya2005 in forum What's Wrong With My Code?
    Replies: 13
    Last Post: December 7th, 2012, 11:39 AM
  4. Need help to complete my assignment.
    By wildwhitecat in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 8th, 2012, 05:19 PM
  5. How to complete code
    By Shay in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 5th, 2010, 01:59 PM