Results 1 to 11 of 11

Thread: private array

  1. #1
    tnght is offline Member
    Join Date
    Nov 2009
    Posts
    6
    Rep Power
    0

    Default private array

    (ii) The Cca class represents a Cca offered by the school. It has the following attributes:
    a) ccaID (String) : an id that uniquely identifies a Cca
    b) name (String) : name of the Cca (e.g. Archery)
    c) numOfVacancy (int) : number of vacancies available in the Cca
    d) studentList : an array of Student currently involved in the Cca
    e) minEntryCgpa (double) : the minimum entry cgpa

    The Cca class has the following constructor and methods:
    • The constructor takes in arguments for attributes a) to e) above, and initializes all its internal attributes respectively. You may assume that there will be 100 students at most for each Cca.
    • Methods for Cca class:

    Name of class Cca
    Name of methods getCcaID, getName, getNumOfVacancy, setNumOfVacancy, setMinEntryCgpa, getMinEntryCgpa, updateStudentList, displayStudentList, toString

    • toString() method will display the values of the ccaID, name, and number of vacancies only.
    • updateStudentList () method will take as input a Student and add it to the array of Student.
    • displayStudentList() method will display all the students’ names in the Cca.

    who can help me? and teach me how to do Pls?

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Start by writing the Cca class with the stated fields and methods.

    P.S When I learned Java they didn't tell me what methods or properties to put in there. Just a problem description requiring a solution. You guys are blessed.

  3. #3
    tnght is offline Member
    Join Date
    Nov 2009
    Posts
    6
    Rep Power
    0

    Default

    i know how to know, but i dont know how to update.....only that part i dont know.

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    The specs say "updateStudentList () method will take as input a Student and add it to the array of Student."
    What have you done for it?

  5. #5
    tnght is offline Member
    Join Date
    Nov 2009
    Posts
    6
    Rep Power
    0

    Default

    public class CCa {

    private String ccID;
    private String name;
    private int numOfVacancy;
    private int[] studentList;

    public CCa( String ccID, String name, int numOfVacancy, int[] studentList)
    {
    this.ccID = ccID;
    this.name = name;
    this.numOfVacancy = numOfVacancy;
    this.studentList = studentList;
    }
    public String getCcID() {
    return ccID;
    }
    public String getName() {
    return name;
    }
    public int getNumOfVacancy() {
    return numOfVacancy;
    }
    public int[] getStudentList() {
    return studentList;
    }
    public void updateStudentList(Student s) {
    }
    public void displayStudentList() {

    for (int i = 0; i < studentList.length; i++)
    {
    }
    System.out.println(studentList);
    }
    public String toString() {
    String info = "\nCCID "+ccID+"\nName "+name+"\nNum Of Vacancy "+numOfVacancy+"\nStudent List "+studentList;
    return info;
    }
    }

  6. #6
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    5

    Default

    Looks good so far. Quick question, is the array of students going to be dynamic or have a set size? If it is set, updateStudentList() should determine the next empty slot and store the paramaters there. to get the next free slot, you could run a while loop each time, or you could have a variable called studentCount. Please ask specific questions too, that way we know what answer you are expecting.

  7. #7
    Crapman is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    Default

    Hello tnght! My TP friend!

    The answer to how to update the student list is in your Lab 5.
    Please go and read up on your lab.

    Oh btw, can I know your course?

  8. #8
    tnght is offline Member
    Join Date
    Nov 2009
    Posts
    6
    Rep Power
    0

    Default

    Cyber and Ditial security, how about u?

  9. #9
    Crapman is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    Default

    Ahhhh, CDS is a nice course. The course name is nice. The course seems to teach nice stuffs. What a nice course. I love CDS.

    Okay, this is going off-topic.

    So I'm gonna explain how to do updateStudentList(Student stud) if not we will just be chatting.
    For updateStudentList(Student stud), u nid to use a loop and a if null to find if there is a space in studentList(), then u set the studentList[i] to be the stud and you break out of the loop. Since the req didnt ask for a return, the return type is void.


    Leung Zhi An from C233 asks "who are you?" <<-- I'm not him. I as dumb as he is.=X


    Edit: I forgot to say what course I'm from. I'm also from CDS =D
    Last edited by Crapman; 11-29-2009 at 10:37 AM.

  10. #10
    tnght is offline Member
    Join Date
    Nov 2009
    Posts
    6
    Rep Power
    0

    Default

    Thanks for the help. :) i from C232 class. :D

  11. #11
    tnght is offline Member
    Join Date
    Nov 2009
    Posts
    6
    Rep Power
    0

    Default

    addStudentToExercise Takes in a Student object as argument and adds it to the cca exercise. (Hint: You need to update the appList)
    getStudentInExercise Accepts the nric as argument and returns the corresponding Student object in the cca exercise. Otherwise return null.
    displayAllStudents This method accepts no input and prints all the students’ details currently in the cca exercise.
    addCca Takes in a Cca object as argument and adds it to the cca excercise.
    removeCca This method accepts the ccaID of the Cca as argument and removes the Cca associated with this ccaID. It returns true if the removal is successful; otherwise returns false.
    removeCca This method accepts no input. It removes those Ccas whose studentList is empty. And, it returns the total number of Ccas that it has removed from the cca excercise.
    getCca Accepts the ccaId as argument and returns the Cca associated with this ccaId. Returns null if not found.
    displayAllCcas This method accepts no input and prints all the ccas’ details in the cca exercise.
    findMostVacancyCca This method returns the Cca object with the most vacancies.
    findLeastVacancyCca This method returns the Cca object with the least vacancies.
    displayAllStudentsAllCca This method will display all the students in all the ccas in the school.
    displayNumberPerCca This method will display the number of students currently in each cca
    processApplications This method accepts no input and it will process all the students’ applications for ccas in the cca excercise. .

    A student’s application for a cca is successfully processed
    ( i.e. the student is assigned to the cca that he/she applies for )
    if the following conditions are true:
     number of vacancy of the cca is not zero
     the student’s cgpa is larger than or equal to the minEntryCgpa

    If a student’s application is successfully processed (i.e. the student is assigned to the cca that he/she applies for), the method will reduce the number of vacancies of that cca by 1. Then, the method must add the student to the studentList of that cca and remove the student from the appList of the cca excercise. .

    How to do?


    public class CcaExercise {
    private String academicYear;
    private String semester;
    private Student[] appList;
    private Cca[] ccaList;

    public CcaExercise (String academicYear, String semester, Student[] appList, Cca[] ccaList)
    {
    this.academicYear = academicYear;
    this.semester = semester;
    this.appList = appList;
    this.ccaList = ccaList;
    }
    public void addStudentToExercise(String student)
    {
    for(int i=0; i<appList.length; i++) {
    if (appList[i]!=null) {
    if (appList[i].getName().equals(name)) {
    appList[i] = null;
    }}}
    }
    public String getStudentInExercise(String nric)
    {
    for (int i=0; i<ccaList.length; i++){
    if (student==studentList)
    {
    return student;
    }
    return null;
    }
    }
    public void dispalyAllStudent()
    {
    System.out.println(student);
    }
    public String addCca(Cca c)
    {
    addCca = addCca + Cca;
    }
    public String removeCca(String ccaID)
    {
    if(ccaID==true)
    {
    System.out.println("remove successful");
    return true;
    }
    else
    {
    System.out.println("remove not successful");
    return false;
    }
    }
    public String getCca(String ccaID)
    {
    if(ccaID==true)
    {
    }
    else
    {
    return null;
    }
    }
    public void diplayAllCcas()
    {
    System.out.println(ccaID);
    }
    public void displayNumberPerCca()
    {
    System.out.println(numberOfCcas);
    }
    }

Similar Threads

  1. More than one input in one private method
    By rice in forum New To Java
    Replies: 0
    Last Post: 10-02-2009, 06:08 AM
  2. Is it acceptable to use a private object?
    By saul_2110 in forum New To Java
    Replies: 8
    Last Post: 12-08-2008, 07:04 PM
  3. Private Classes Clarification
    By justlearning in forum New To Java
    Replies: 1
    Last Post: 05-06-2008, 11:51 PM
  4. Private main method
    By bugger in forum New To Java
    Replies: 1
    Last Post: 12-21-2007, 10:45 AM
  5. Question of private member
    By Felissa in forum Advanced Java
    Replies: 2
    Last Post: 06-28-2007, 10:08 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
  •