student information

must add, delete, change, and show student information

Page 1 of 1

9 Replies - 2055 Views - Last Post: 01 May 2010 - 03:38 PM Rate Topic: -----

#1 Guest_kevin*


Reputation:

student information

Posted 29 April 2010 - 10:33 PM

in this program i must add student info: ssn, course, grade, address, campus, name, major, age,status, gpa. then grab the course or courses and add the grade and status. then choice to delete or upgrade the students infomation. and i must be able ti find the students by ssn and/or grade or major. the methods i have create are the implements a interface class. am unable to display and find the students info. i have missing return statements in some methods. i can seem to put both search and find statements right.

this is the code

public class DataManagerBean implements DataManager {

    public void addStudent(Student student) throws StudentException {



        boolean cont = true;
        ArrayList<Student> students = new ArrayList<Student>();

        while (cont) {

            String age = JOptionPane.showInputDialog("age");
            int ages = Integer.parseInt(age);

            String major = JOptionPane.showInputDialog("major");
            String name = JOptionPane.showInputDialog("name");
            String GPA = JOptionPane.showInputDialog("GPA");
            double GPAs = Integer.parseInt(GPA);

            String ssn = JOptionPane.showInputDialog("ssn");
            String campus = JOptionPane.showInputDialog("campus");
            String address = JOptionPane.showInputDialog("address");


            Student student1 = new Student();

            student1.setAge(ages);
            student1.setMajor(major);
            student1.setName(name);
            student1.setGPA(GPAs);
            student1.setSsn(ssn);
            students.add(student1);

            HCC student2 = new HCC(campus, address);

            student2.setAddress(address);
            student2.setCampus(campus);
            students.setHCC(student2);



            int concour = JOptionPane.showConfirmDialog(null, "more courses ? ");

            if (concour >= 1) {


                String course = JOptionPane.showInputDialog("course");
                String status = JOptionPane.showInputDialog("status");

                ArrayList<Student> courses = new ArrayList<Student>();


                courses.setCourse(courses);
                courses.setStatus(status);
                student1.setCourses(courses);
            }


            int confirm = JOptionPane.showConfirmDialog(null, "Do u want to cont? ");

            if (confirm > 0) {
                cont = false;
            }


        }

    }

    public void addGrade(String ssn) {
        boolean cont1 = true;
        ArrayList<Student> course = new ArrayList<Student>();
 int confirm = JOptionPane.showConfirmDialog(null, "Do u want to cont? ");

        while (cont1) {


            String grade = JOptionPane.showInputDialog("grade");
            double grades = Integer.parseInt(grade);



            Course courses = new Course();


            courses.setGrade(grades);

            course.add(courses);

            int confirm = JOptionPane.showConfirmDialog(null, "Do u want to cont? ");

            if (confirm > 0) {
                cont1 = false;
            }


        }
    }

    public void deleteStudent(String ssn) {
        JOptionPane.showMessageDialog(null, "In Delete");
        ArrayList<Student> studentsToBeRemoved = new ArrayList<Student>();

        for (Student student : studentsToBeRemoved) {

            if (student.getSsn().equals(ssn)) {

                studentsToBeRemoved.add(student);
            }
        }

        for (Student student : studentsToBeRemoved) {
            studentsToBeRemoved.remove(student);
        }

        JOptionPane.showMessageDialog(null, "Delete completed");
//        studentsToBeRemoved();
    }

    public void updateStudentProfile(Student student) throws StudentException {
    }

    public Student findStudent(String ssn) throws StudentException {
        int search = JOptionPane.showConfirmDialog(null, "Do u want to search? ");
        if (search == 0) {
            String searchName = JOptionPane.showInputDialog("Enter ssn .. ?");
//            addGrade(ssn, searchName);
        }
        try {
            throw new Exception("Error");
        } catch (Exception ex) {
            Logger.getLogger(DataManagerBean.class.getName()).log(Level.SEVERE, null, ex);

        }
    }

    public List<Student> findStudentsByGradesAndMajor(double grade, String major) throws StudentException {
        int search = JOptionPane.showConfirmDialog(null, "Do u want to search? ");
        if (search == 0) {
            String searchName = JOptionPane.showInputDialog("Which student .. ?");
            displayStudentInfomation(grade, searchName);
        }
        
 
        JOptionPane.showMessageDialog(null, s.getMajor());
    

        for (Student c : y) {
            JOptionPane.showMessageDialog(null, c.getMajor());
        }
    

        for (Student c : y) {
            if (c.getName().equals(nameType)) {
                JOptionPane.showMessageDialog(null, "His major is " + c.getMajor() + " and his " + c.getAge());
            }


        }
    }
}
  


Is This A Good Question/Topic? 0

Replies To: student information

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1658
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: student information

Posted 29 April 2010 - 10:35 PM

So is this you?
Was This Post Helpful? 0
  • +
  • -

#3 Guest_kevin*


Reputation:

Re: student information

Posted 30 April 2010 - 06:21 PM

What to u mean is this me? this is my project.
Was This Post Helpful? 0

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1658
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: student information

Posted 30 April 2010 - 06:51 PM

So I guess you didn't click the provided link to see the code there (from several years ago) is identical to what you posted? Was what you posted the code that was provided by your instructor?
Was This Post Helpful? 0
  • +
  • -

#5 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1014
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: student information

Posted 30 April 2010 - 06:58 PM

you have declared the findStudent method as:
public Student findStudent(String ssn) throws StudentException { 

which means it should return a Student Object.
you have to add a return statement to that method. as the method seems, it should return the Student if found, or throw an exception if not.

same thing for your findStudentsByGradesAndMajor
public List<Student> findStudentsByGradesAndMajor(double grade, String major) throws StudentException {

this method should return a List of Student Objects.

if you are not familiar with methods in java, here is a sun's tutorial:
http://java.sun.com/...eturnvalue.html

*edit - changed the link

This post has been edited by japanir: 30 April 2010 - 07:00 PM

Was This Post Helpful? 0
  • +
  • -

#6 Guest_kevin*


Reputation:

Re: student information

Posted 30 April 2010 - 09:21 PM

View Postkevin, on 30 April 2010 - 05:21 PM, said:

What to u mean is this me? this is my project.


my instructor only provide the implemented methods. and in the link u provide is a follow clssmate. its not the finish version.
Was This Post Helpful? 0

#7 Guest_kevin*


Reputation:

Re: student information

Posted 30 April 2010 - 11:45 PM

i have change the program completely. now everything mostly works but in reverse. when i click no in the continue option GUI it does the opposite of what it has to do. now am able to input the mostly everything but i havent had the chance to input all the students info. now i think i have filled the nessacery statements.

here the new code for the program

public class DataManagerBean implements DataManager
{

    public void addStudent(Student student) throws StudentException {


//   JOptionPane.showInputDialog(StudentCollection.add(student));
    
    }

    public void addGrade(String ssn) {
       
        boolean cont1 = true;
       
       ArrayList<Student> students;
       
       
 int conti = JOptionPane.showConfirmDialog(null, "Do u want to cont? ");

        while (cont1) {


            String grade = JOptionPane.showInputDialog("grade");
            double grades = Integer.parseInt(grade);



            Course courses = new Course();


            courses.setGrade(grades);

           // students.courses;

            int confirm = JOptionPane.showConfirmDialog(null, "Do u want to cont? ");

            if (confirm > 0) {
                cont1 = false;
            }


        }
    }

    public void deleteStudent(String ssn)
    {
        JOptionPane.showMessageDialog(null, "In Delete");
        ArrayList<Student> studentsToBeRemoved = new ArrayList<Student>();

        for (Student student : studentsToBeRemoved) {

            if (student.getSsn().equals(ssn)) {

                studentsToBeRemoved.add(student);
            }
        }

        for (Student student : studentsToBeRemoved) {
            studentsToBeRemoved.remove(student);
        }

        JOptionPane.showMessageDialog(null, "Delete completed");
//        studentsToBeRemoved();
    }

    public void updateStudentProfile(Student student) throws StudentException 
    {

        
        
        
        
        
        
    }
    

    public Student findStudent(String ssn) throws StudentException
    {
        int search = JOptionPane.showConfirmDialog(null, "Do u want to search? ");
        if (search == 0) {
            String searchName = JOptionPane.showInputDialog("Enter Ssn .. ?");
            findStudent(ssn);
        }

        Student s = null;

        JOptionPane.showMessageDialog(null, s.getSsn());


        ArrayList<Student> y = null;

        for (Student c : y) {
            JOptionPane.showMessageDialog(null, c.getSsn());
        }

        String nameType = null;



        for (Student c : y) {
            if (c.getName().equals(nameType)) {
                JOptionPane.showMessageDialog(null, "His major is " + c.getName() + " and his " + c.getSsn());
            }
        }


        throw new UnsupportedOperationException("Error student no found");
    }

    public List<Student> findStudentsByGradesAndMajor(double grade, String major) throws StudentException
    {
         int search = JOptionPane.showConfirmDialog(null, "Do u want to search? ");
        if (search == 0) {
            String searchName = JOptionPane.showInputDialog("Enter Ssn .. ?");
            findStudentsByGradesAndMajor(grade, major);
        }

        Student s = null;

        JOptionPane.showMessageDialog(null, s.getSsn());


        ArrayList<Student> y = null;

        for (Student c : y) {
            JOptionPane.showMessageDialog(null, c.getSsn());
        }

        String nameType = null;



        for (Student c : y) {
            if (c.getName().equals(nameType)) {
                JOptionPane.showMessageDialog(null, "His major is " + c.getName() + " and his " + c.getAge());
            }
        }

        throw new UnsupportedOperationException("Error student no found");
            }
        public static void main(String[] args)
        {
    boolean cont = true;
        ArrayList<Student> students = new ArrayList<Student>();

        while (cont) {

            String age = JOptionPane.showInputDialog("age");
            int ages = Integer.parseInt(age);

            String major = JOptionPane.showInputDialog("major");
            String name = JOptionPane.showInputDialog("name");
            String GPA = JOptionPane.showInputDialog("GPA");
            double GPAs = Integer.parseInt(GPA);

            String ssn = JOptionPane.showInputDialog("ssn");
            String campus = JOptionPane.showInputDialog("campus");
            String address = JOptionPane.showInputDialog("address");


            Student student1 = new Student();

            student1.setAge(ages);
            student1.setMajor(major);
            student1.setName(name);
            student1.setGPA(GPAs);
            student1.setSsn(ssn);
            students.add(student1);

            HCC student2 = new HCC(campus, address);

            student2.setAddress(address);
            student2.setCampus(campus);
           // students.setHCC(student2);



            int concour = JOptionPane.showConfirmDialog(null, "more courses ? ");

            if (concour >= 1) {


                String course = JOptionPane.showInputDialog("course");
                String status = JOptionPane.showInputDialog("status");

                Course courses = new Course();


                courses.setCourses("courses");
                courses.setStatus(status);
   //             student1.setCourses();
            }


            int confirm = JOptionPane.showConfirmDialog(null, "Do u want to cont? ");

            if (confirm > 0) {
                cont = false;
            }


        }

    }
}


Was This Post Helpful? 0

#8 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1014
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: student information

Posted 01 May 2010 - 02:40 AM

Quote

when i click no in the continue option GUI it does the opposite of what it has to do

what is the continue option GUI? what do you expect it to do, and what do you get instead?
Was This Post Helpful? 0
  • +
  • -

#9 Guest_kevin*


Reputation:

Re: student information

Posted 01 May 2010 - 11:52 AM

View Postjapanir, on 01 May 2010 - 01:40 AM, said:

Quote

when i click no in the continue option GUI it does the opposite of what it has to do

what is the continue option GUI? what do you expect it to do, and what do you get instead?


the continue option or the search is when if i would like to add the students info then add the courses which i should add the grade and status then search the student if i want to delete the added student or not. then to continue i need to search the student if theres is a student by there ssn or by their major or grade. thats what i expect it to do but it doesnt when i choice to contniue it doesnt and basically when i click yes to search or continue the program stops.
Was This Post Helpful? 0

#10 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1014
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: student information

Posted 01 May 2010 - 03:38 PM

I have noticed couple of logic errors in your code.
the first error I noticed is in the addGrade method.
notice that for each iteration of the while loop you create a new Courses Object. that Object exists only in the current iteration of the loop. then it;s "lost" and you declare a new Courses Object. so you actually save none of the grades you set to that Courses Object.
i suggest that you create a global Courses Object, and add the variables to it (instead of creating the Object in the loop).

second problem I noticed is in the deleteStudent method.
you go over the studentsToBeRemoved List, and find the Student Object to be removed. when you find it, you add it again to the same list (studentsToBeRemoved).
then you go over the StudentsToBeRemoved List, and delete all Objects from it.
not the best approach i'd say...
why not remove the student object from the list of students instead of creating a new list, add new objects to it, and then empty it?

think about what i said and see how you fix those.
then post your updated code if you still have any questions or problems with the program.
hope i could help :)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1