Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Bronze (1000 achievement points), Silver (2000 achievement points), Gold (3000 a

ID: 3538013 • Letter: B

Question

Bronze (1000 achievement points), Silver (2000 achievement points), Gold (3000 achievement points),, Platinum (4000 or more achievement points), are used to represent levels of achievement in the rolling hill day camp. Create an enumerated type to represent the achievement levels. Write a Camper class that will include a method to assign the right type to a private variable of that type and another method to return a String telling the calling class the points achieved base upon the enumerated type.

Explanation / Answer

class Camper {
    //name of the camper
    String name;
    //name of the sports which is participated by camper
    String sportType;
    //camper archievement
    Achievement achievement;
   
    public Camper(){
       
    }
   
    public Camper(String name){
        this.name = name;
    }
   
    public Camper(String name, String sportType){
        this.name = name;
        this.sportType = sportType;
    }
   
    public String getSportType() {
        return sportType;
    }

    public void setSportType(String sportType) {
        this.sportType = sportType;
    }

    public String getName(){
        return name;
    }

    public void setAchievement(Achievement achievement) {
        this.achievement = achievement;
    }

    public Achievement getAchievement(){
        return achievement;
    }
   
    //this will return the points achieved by camper.
    //If he is not achieved anything, This will return 0.
    public int getPoints(){
        if(achievement != null){
            return achievement.getPoints();
        }
       
        return 0;
    }
   
    //this will return the total details of the camper.
    public String toString(){
        String content ="-------------------------- " +
                        "Name : " + getName() + " " +
                        "Sport participated : " + getSportType() +" " +
                        "Achieved : " + achievement.getAchievement() +" " +
                        "Points : " + achievement.getPoints() +" " +
                        "-------------------------- ";
       
        return content;
               
    }
}

//This is enum representing Achievement.
enum Achievement{
    BRONZE("Bronze", 1000),
    SILVER("Silver", 2000),
    GOLD("Gold", 3000),
    PLATINUM("Platinum", 4000),
    //If the campers are more than 4 for specific sports type
    //after from 5th person, It will be NOT_ACHIEVED.
    //we have only 4 grads, we can assign above grads to first 4 campers
    NOT_ACHIEVED("Not Achieved", 0);
   
    String achievement;
    int points;
    private Achievement(String achievement, int points){
        this.achievement = achievement;
        this.points = points;
    }
   
    public String getAchievement(){
        return achievement;
    }
   
    public int getPoints(){
        return points;
    }
}

//This class will test the Camper implementation.
public class Test{
    public static void main(String args[]){
        //Creating 4 campers with sports type sportType1
        Camper c1 = new Camper("john", "sportType1");
        Camper c2 = new Camper("peter", "sportType1");
        Camper c3 = new Camper("annie", "sportType1");
        Camper c4 = new Camper("great", "sportType1");
       
        //Set the achievement of the campers.
        c1.setAchievement(Achievement.GOLD);
        c2.setAchievement(Achievement.BRONZE);
        c3.setAchievement(Achievement.PLATINUM);
        c4.setAchievement(Achievement.SILVER);
       
        System.out.println(c1);
        System.out.println(c2);
        System.out.println(c3);
        System.out.println(c4);
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote