Write a Java program for NetBeans that creates a ProfessorRating class consistin
ID: 3713623 • Letter: W
Question
Write a Java program for NetBeans that creates a ProfessorRating class consisting of professor ID and three ratings. The three ratings are used to evaluate easiness, helpfulness, and clarity. The value for each rating is in the range of 1 to 5, with 1 is the lowest and 5 is the highest. Test this class in main () method by creating an instance of ProfessorRating, allow user to enter the value for each rating and display the overall rating. Include appropriate constructors and getter/setter methods for each data member in ProfessorRating class. Do not allow the professor ID to be changed after an object has been constructed. Provide a method calcRating () to compute and return the overall rating average , and displayResult() method to display all ratings and the average rating formatted with no decimal points. IMPORTANT: CREATE THIS PROJECT IN NETBEANS AND NAME IT: FirstName_LastName_A6.java
I posted this question once already and was confused by the answers. Does this assignment want me to turn in two separate codes? How can there be more than one public class. I really need help. Please be available for questions after the answer is posted. I will be happy to thumbs up.
Explanation / Answer
Only one class is needed. Below is your code
public class ProfessorRating {
private int ID;
private int rating1, rating2, rating3;
public ProfessorRating() {
}
public ProfessorRating(int ID, int rating1, int rating2, int rating3) {
this.ID = ID;
this.rating1 = rating1;
this.rating2 = rating2;
this.rating3 = rating3;
}
public int getID() {
return ID;
}
public int getRating1() {
return rating1;
}
public void setRating1(int rating1) {
this.rating1 = rating1;
}
public int getRating2() {
return rating2;
}
public void setRating2(int rating2) {
this.rating2 = rating2;
}
public int getRating3() {
return rating3;
}
public void setRating3(int rating3) {
this.rating3 = rating3;
}
double calcRating() {
return (rating1 + rating2 + rating3) / 3.0;
}
void displayResult() {
System.out.println("Rating 1 : " + getRating1());
System.out.println("Rating 2 : " + getRating2());
System.out.println("Rating 3 : " + getRating3());
System.out.println("Average rating : "+Math.round(calcRating()));
}
public static void main(String args[]) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter ID: ");
int id = scanner.nextInt();
System.out.println("Enter rating1: ");
int rating1 = scanner.nextInt();
System.out.println("Enter rating2: ");
int rating2 = scanner.nextInt();
System.out.println("Enter rating3: ");
int rating3 = scanner.nextInt();
ProfessorRating professorRating = new ProfessorRating(id, rating1, rating2, rating3);
professorRating.displayResult();
}
}
Output
Enter ID:
232
Enter rating1:
2
Enter rating2:
3
Enter rating3:
4
Rating 1 : 2
Rating 2 : 3
Rating 3 : 4
Average rating : 3
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.