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 17 of 17

Thread: I need to create a class that coordinates all the others and don't know what it means

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I need to create a class that coordinates all the others and don't know what it means

    Hello I have an assignment, and I need to create this class that i guess puts everything together. Everything that I have done it was writting by the professor,i guess I just need an extra class to make it all work?? Here is the code:

    package assignment1hectorfarinas;
     
    import java.util.ArrayList;
    import javax.swing.JOptionPane;
     
    public class Main {
     
     
        String str = JOptionPane.showInputDialog("Read data");
        double x = Double.parseDouble(str);
     
        public static void main(String[] args) {
     
     
     
            boolean done = false;
            String menu = "1- Add\n2- Drop Student\n3- Display Information\n4- Change Name\n5-Modify Course\na) Add\nb) Drop\n6- Quit";
            Admission current = new Admission();
            Admission drop = new Admission();
     
            while (!done) {
                int i = getData.getInt(menu);
                switch (i) {
                    case 1:
                        String f = getData.getWord("Enter name");
                        String m = getData.getWord("Enter middle name");
                        String l = getData.getWord("Enter last name");
                        Name n = new Name(f, m, l);
                        String street = getData.getWord("Enter street address");
                        String city = getData.getWord("Enter city");
                        int zip = getData.getWord("Enter zip code");
                        String state = getData.getWord("Enter state");
                        Address addr = new Address(street, city, zip, state);
                        String id = getData.getWord("Enter id number");
                        Student s = new Student(n, addr, id);
                        current.search(id);
     
                        if (!current.empty()) {
                            current.search(id);
                            if (!current.inList()) {
                                current.add(s);
                            } else {
                                System.out.println("Error. Try again");
                            }
                        }
                    case 2:
                        if (!current.empty()) {
                            String idnum = getData.getWord("Enter id number");
                            current.search(idnum);
                            if (!inList()) {
                                System.out.println("Nothing found");
                            } else {
                                int i = current.getIndex();
                                Student s = current.remove(i);
                                drop.add(s);
                            }
     
                        }
                    case 3:
                        ArrayList list = current.getTheList();
                        String ns = " ";
     
                        for (int h = 0; h > list.size(); h++) {
                            Student st = list.get(i);
                            ns = ns + st.getId() + st.getName() + st.getAddr() + st.getD();
                        }
     
     
     
     
                }
            }
        }
    }

    package assignment1hectorfarinas;
     
    import java.util.Date;
    import java.util.jar.Attributes.Name;
     
     
    public class Student {
     
        Name name;
        Address addr;
        String id;
        Date d;
     
        //Constructor
        public Student(Name name, Address addr, String id, Date d) {
            this.name = name;
            this.addr = addr;
            this.id = id;
            this.d = d;
        }
     
        //Getter methods to return what we want
        public Address getAddr() {
            return addr;
        }
     
        public Date getD() {
            return d;
        }
     
        public String getId() {
            return id;
        }
     
        public Name getName() {
            return name;
        }
    }

    package assignment1hectorfarinas;
     
    public class Name {
     
        String first, middle, last;
     
        //Constructor
        public Name(String first, String middle, String last) {
            this.first = first;
            this.middle = middle;
            this.last = last;
        }
     
        //Getter methods
        public String getFirst() {
            return first;
        }
     
        public String getLast() {
            return last;
        }
     
        public String getMiddle() {
            return middle;
        }
     
        void changeLastName(String l) {
            last = l;
        }
    }

    package assignment1hectorfarinas;
     
    public class Address {
     
        String street, city, state;
        int zip;
     
        public Address(String street, String city, String state, int zip) {
            this.street = street;
            this.city = city;
            this.state = state;
            this.zip = zip;
        }
     
        //Getter methods
        public String getCity() {
            return city;
        }
     
        public String getState() {
            return state;
        }
     
        public String getStreet() {
            return street;
        }
     
        public int getZip() {
            return zip;
        }
    }

    package assignment1hectorfarinas;
     
     
     
    public class Admission {
     
        Arraylist <Student> list;
        Student s;
        boolean found;
        int index;
     
        Admission(){
        list = new ArraList <Student>();
        }
     
        void add(Student s) {
            list.add(s);
        }
     
        Student remove(int i) {
            return list.remove(i);
        }
     
        Student getStudent() {
            return s;
        }
     
        boolean inList() {
            return found;
        }
     
        int getIndex() {
            return index;
        }
     
        //Search for student by id
        void search(String id) {
            found = false;
            int i = 0;
            while (i < list.lenght && !found) {
                Student st = list.get(i);
                if (id.equalsIgnoreCase(st.getId())) {
                    s = st;
                    found = true;
                    index = i;
                }
                i++;
            }
        }
    }

    So far I have my main class, Student, Name, Address and Admission . I need to create a class that syncs everything?
    With this class I need to : - Create a student and add it to the Array
    - Remove a student
    - Change a student last name
    - Display all students added
    - Display students removed

    Thanks in advanced.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I need to create a class that coordinates all the others and don't know what it m

    I need to create a class that syncs everything?
    I'm not sure what you mean by "syncs everything".
    What does your Main class do? It looks like it has a menu that allows a user to do the different functions that you list at the end of your post.

  3. #3
    Junior Member
    Join Date
    Jan 2011
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I need to create a class that coordinates all the others and don't know what it m

    i need help with my last class that performs the following :
    - Remove a student
    - Change a student last name
    - Display all students added
    - Display students removed

    Then I guess from the main class I call/display everything in a Joption pane which is what I have written?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I need to create a class that coordinates all the others and don't know what it m

    Are all those tasks listed as menu options in the Main class?
    Do you have any specific questions about any of the tasks?

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I need to create a class that coordinates all the others and don't know what it m

    Your code does not compile.
    For example there is no definition for the variable: getData

  6. #6
    Junior Member
    Join Date
    Jan 2011
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I need to create a class that coordinates all the others and don't know what it m

    I need a menu that each option performs a task. I think that menu is already written in the main class?? I don't know why the Professir had that getData there because like you said it is not define and yes it does not compile. He wants us to create a class called test that coordinates the activities of all the classes I have shown above. Maybe i need to define that getData object here along with all methods performing all tasks? I just don't know how to link or access data from class to class and make it work in main.
    Last edited by kl2eativ; September 10th, 2011 at 05:55 PM.

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I need to create a class that coordinates all the others and don't know what it m

    Get the posted code to compile and execute first.

    Then figure out what the code does and what you need to add to it to do your assignment.

  8. #8
    Junior Member
    Join Date
    Jan 2011
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I need to create a class that coordinates all the others and don't know what it m

    Good idea, but can you give me an idea of what getData is suppose to do so i can define it?

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I need to create a class that coordinates all the others and don't know what it m

    Look at what the parameters to the getData method are and what it returns.
    It asks the user a question and returns his response.

  10. #10
    Junior Member
    Join Date
    Jan 2011
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I need to create a class that coordinates all the others and don't know what it m

    What is this trying to do ??
    getData.getWord("Enter name");
    getData.getWord("Enter middle name");

    .getWord does this even exists?

    I need to define getData in the main class and I can do it in another class?

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I need to create a class that coordinates all the others and don't know what it m

    getData is a reference to an instance of a class that has the getWord and getInt methods.

    Ask the person you got the code from for a definition of that class.

  12. #12
    Member
    Join Date
    Sep 2011
    Location
    United States
    Posts
    30
    My Mood
    Fine
    Thanks
    0
    Thanked 6 Times in 5 Posts

    Default Re: I need to create a class that coordinates all the others and don't know what it m

    Ok, so I took an interest in this thread since I have come across issues like this with other java students. Basically, your teacher decided to leave a bunch of holes, including some typos, in this assignment. I went ahead and worked it out on my computer so that options 1-3 and 6 work and I must say it was kind of a pain. The easiest way I can put it is that if something is coming up as undefined then you have to create it. This means you may have to edit something in each of the classes. As for the whole getData bit, I just made a getData class to hold all of the methods (which i just made static) that are called by that object. Whether my method for getting this done was correct per you professors train of thought, I do not know. Did you get something like a complete outline for the assignment, that would be helpful in figuring out how to go about this. As for what the getWord() and getInt() do is bring up a JOptionPane and wait for user input each time they are called. Hope this helps.

  13. #13
    Junior Member
    Join Date
    Jan 2011
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I need to create a class that coordinates all the others and don't know what it m

    Yes the last part of the Assignment is to create another class called test that "coordinates the activities of the classes outlined above by:
    - Creating a student and adding it to the database
    - Remove a student
    - Change a student last name
    - Display all students added
    - Display students removed

    I guess in this class is were I define all my methods??

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I need to create a class that coordinates all the others and don't know what it m

    Not necessarily. You will probably need to add methods to each of the classes you currently have.

    First you need a design or definition for what the "testing" class is supposed to do. Is it to replace the Main class which already does some of the functions?

  15. #15
    Member
    Join Date
    Sep 2011
    Location
    United States
    Posts
    30
    My Mood
    Fine
    Thanks
    0
    Thanked 6 Times in 5 Posts

    Default Re: I need to create a class that coordinates all the others and don't know what it m

    If you made a class Test you could create an instance of it called getData. It's basically the same way I coded it except I made a class getData which seems to be incorrect going by the outline. As for adding methods to the other classes, you will need to but there are only a few methods/modifications that need to be made.
    Last edited by SerratedMind; September 10th, 2011 at 08:51 PM.

  16. #16
    Junior Member
    Join Date
    Jan 2011
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I need to create a class that coordinates all the others and don't know what it m

    Quote Originally Posted by Norm View Post
    Not necessarily. You will probably need to add methods to each of the classes you currently have.

    First you need a design or definition for what the "testing" class is supposed to do. Is it to replace the Main class which already does some of the functions?
    this is what it says for the test class:
    Provide a test class that "coordinates the activities of the classes outlined above by:
    - Creating a student and adding it to the database
    - Remove a student
    - Change a student last name
    - Display all students added
    - Display students removed

  17. #17
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I need to create a class that coordinates all the others and don't know what it m

    Compare that list with what the Main class's menu does:
    String menu = "
    1- Add\n
    2- Drop Student\n
    3- Display Information\n
    4- Change Name\n
    5-Modify Course\n
    a) Add\n
    b) Drop\n
    6- Quit";

Similar Threads

  1. JAVA problem : Create a Fan Class
    By broo7198 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 9th, 2011, 12:23 AM
  2. In a class create an array list of elements of another class, help!
    By LadyBelka in forum Collections and Generics
    Replies: 3
    Last Post: May 4th, 2011, 05:00 PM
  3. Replies: 2
    Last Post: January 22nd, 2011, 11:20 PM
  4. How to create a new object of another class within a method
    By davie in forum Object Oriented Programming
    Replies: 1
    Last Post: April 16th, 2010, 05:53 PM
  5. help with problem havr no idea what it means
    By mdstrauss in forum Exceptions
    Replies: 4
    Last Post: July 27th, 2009, 12:41 AM