Answer to Question #272688 in Java | JSP | JSF for bikki

Question #272688

Build a class Project with id(int) , desc (String), duration (int) , budget (double) and members (ArrayList of Workers). a. Provide a parameterized constructor Project (int id, String desc, double budget). The member array will be initialized as empty array and the initial duration of the project will be 0 b. Provide setters for description and budget and getters for all except members list c. Provide a method addMember(Worker m) that adds the worker instance to the members array list d. Provide a method Worker getMember(int wId) that searches for the worker with the given id in the members list and returns instance.  


1
Expert's answer
2021-11-29T18:46:05-0500

SOLUTION CODE

 class Project {
    int id;
    String desc;
    int duration;
    double budget;
    // Create an ArrayList object
    ArrayList<String> workers = new ArrayList<String>();
    //parameterised constructor
    Project(int id, String desc, double budget) {
        this.id = id;
        this.desc = desc;
        this.budget = budget;
    }
    //setter methods
    public void setDuration()
    {
        //set duration to 0
        duration = 0;
    }
     public void setBudget(double b)
     {
         budget = b;
     }
     //getters

     public double getBudget() {
         return budget;
     }
     public int getDuration()
     {
         return duration;
     }


     //add member function
    public void AddMember(String m)
    {
        workers.add(m);
    }

    public String getMember(int n)
    {
        return workers.get(n);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS