public class ScienceFairProject { // these are the instance variables/ private static String projectName; private static String contestantName; private int score; static int projectA = 0; static int projectB=0; static int projectC=0; static int projectD=0; public static String getProjectName() { return projectName; } public static String getContestantName() { return contestantName; } public int getScore() { return score; } /** * Precondition: score starts with zero * Postcondition: score will keep track of how many of each score the person got */ public void setAddScore() { if (score<2) projectA++; else if ((score>1)&&(score<3)) projectB++; else if ((score>2)&&(score<4)) projectC++; else projectD++; } /** * Precondition: each project must have a score * Postcondition: will find the score most given */ public static int getAverage() { if (projectA>projectB) return 1; else if (projectB>projectC) return 2; else if (projectC>projectD) return 3; else return 4; } public void setProjectName(String newProjectName) { projectName=newProjectName; } public void setContestantName(String newContestantName) { contestantName=newContestantName; } public void getScore(int newScore) { score=newScore; } }
public class ScienceFairProjectMain { public static void main (String[] args) { //project scores have been entered// ScienceFairProject project1 =new ScienceFairProject(); project1.setProjectName("Earth"); project1.setContestantName("Ben"); project1.getScore(1); ScienceFairProject project2 =new ScienceFairProject(); project2.setProjectName("Earth"); project2.setContestantName("Ben"); project2.getScore(1); ScienceFairProject project3 =new ScienceFairProject(); project3.setProjectName("Earth"); project3.setContestantName("Ben"); project3.getScore(1); ScienceFairProject project4 =new ScienceFairProject(); project4.setProjectName("Earth"); project4.setContestantName("Ben"); project4.getScore(1); ScienceFairProject project5 =new ScienceFairProject(); project5.setProjectName("Earth"); project5.setContestantName("Ben"); project5.getScore(1); ScienceFairProject project6 =new ScienceFairProject(); project6.setProjectName("Earth"); project6.setContestantName("Ben"); project6.getScore(1); /** * Precondition: will take all information * Postcondition: the project name, contestant and the average score will be written on the screen */ System.out.println("Project Name: "+ScienceFairProject.getProjectName()); System.out.println("Contestant Name: "+ScienceFairProject.getContestantName()); System.out.println("The average score is "+ScienceFairProject.getAverage()); } }
My out put is OK for the Project & Contestant Name, but the Average Score is not calculating correctly. it keeps returning 4.