Feedback Manipulation program in java

In this post, we will learn Feedback Manipulation program in java Programming language.

Question:

The OX-FO college now wants to automate the feedback entered by the students for the faculty and the course. The application should be menu driven. Develop an application to implement the scenario.

You are provided with a  Feedback class with the following private attributes:

            int feedbackId

            String courseName

            int facultyId

            int feedbackRating

Necessary public getter and setter methods are provided.

Create a class College which has an  ArrayList of Feedback as attribute as : 

List<Feedback> feedbackList = new ArrayList<Feedback>().  

Write the getter and setter.

 Also College class should have the following methods :

·          public void addFeedback(Feedback  feedbackObj)  –  This method should add the feedback object to the feedbacklist

·          public List<Feedback> viewAllFeedbacks()  –  This method should return the feedbackList.

·          public List<Feedback> viewFeedbackbyCourse(String courseName)  –  This method should return the list of feedback for the given course name. If invalid course name/no feedback for that course is given, it should print “Invalid”.

 ·         public Feedback getHighestFeedback() – This method should return the Feedback that has the highest feedback rating(Assume that the feedback rating is from 1-5 , where 5 being the highest and 1 being the least, also assume that there will be one feedback which will have the highest rating

Create a class TestMain which has the main method.  In the main function write the code to create the menu and invoke the needed functions based on the choice provided.

Design the UI as shown in the samples below.

Sample Input and Output 1:

1.Add Feedback
2.View All Feedback
3.Search Feedback by courseName

4. Get highest Feedback

5.Exit
Enter your choice:
1
Enter the feedback id:
1
Enter the course name:
Java
Enter the faculty id:
100

Enter the feedbackRating:

2

1.Add Feedback
2.View All Feedback
3.Search Feedback by courseName

4. Get highest Feedback

5.Exit
Enter your choice:
1
Enter the feedback id:
2
Enter the course name:
Java
Enter the faculty id:
101

Enter the feedbackRating:

4

1.Add Feedback
2.View All Feedback
3.Search Feedback by courseName

4. Get highest Feedback


5.Exit
Enter your choice:
1
Enter the feedback id:
3
Enter the course name:
Dbms
Enter the faculty id:
103

Enter the feedbackRating:

2

1.Add Feedback
2.View All Feedback
3.Search Feedback by courseName

4. Get highest Feedback


5.Exit
Enter your choice:

2

Feedback Id:1

Course Name:Java

Faculty Id:100

Feedback Rating:2

Feedback Id:2

Course Name:Java

Faculty Id:101

Feedback Rating:4

Feedback Id:3

Course Name:Dbms

Faculty Id:103

Feedback Rating:2

1.Add Feedback
2.View All Feedback
3.Search Feedback by courseName

4. Get highest Feedback

5.Exit
Enter your choice:3

Enter the Course Name:

Dbms

Feedback Id:3

Course Name:Dbms

Faculty Id:102

Feedback Rating:2

1.Add Feedback
2.View All Feedback
3.Search Feedback by courseName

4. Get highest Feedback

5.Exit
Enter your choice:

4

Feedback Id:2

Course Name:Java

Faculty Id:101

Feedback Rating:4

1.Add Feedback
2.View All Feedback
3.Search Feedback by courseName

4. Get highest Feedback

5.Exit
Enter your choice:

5

Thank you for choosing the application

Feedback Manipulation program in java CODE:

TESTmain.java

import java.util.*;
public class TestMain{
    static Scanner sc=new Scanner(System.in);
    public static Feedback getObj()
    {
        Feedback f=new Feedback();
        System.out.println("Enter the feedback id:");
        f.setFeedbackId(sc.nextInt());
        System.out.println("Enter the course name:");
        f.setCourseName(sc.next());
        System.out.println("Enter the faculty id:");
        f.setFacultyId(sc.nextInt());
        System.out.println("Enter the feedbackRating:");
        f.setFeedbackRating(sc.nextInt());
        return f;
    }
    public static void prinObj(Feedback f)
    {
        System.out.println("Feedback Id:"+f.getFeedbackId());
        System.out.println("Course Name:"+f.getCourseName());
        System.out.println("Faculty Id:"+f.getFacultyId());
        System.out.println("Feedback Rating:"+f.getFeedbackRating());
    }
    public static void main(String[] args)
    {
        int cn;
        College c=new College();
        do
        {
            System.out.println("1.Add Feedback\n2.View All Feedback\n3.Search Feedback by courseName\n4.Get highest Feedback\n5.Exit");
            System.out.println("Enter your choice");
            cn=sc.nextInt();
            switch(cn)
            {
                case 1:Feedback f=getObj();
                       c.addFeedback(f);
                       break;
                       case 2:List<Feedback> f1=c.viewAllFeedbacks();
                              for(Feedback i:f1)
                              prinObj(i);
                              break;
                              case 3:System.out.println("Enter the Course Name:");
                              List<Feedback> f2=c.viewFeedbackbyCourse(sc.next());
                              for(Feedback i:f2)
                              prinObj(i);
                              break;
                              case 4:prinObj(c.getHighestFeedback());
                              break;
                              case 5: break;
            }
        }
        while(cn!=5);
        System.out.println("Thank you for choosing the application");
    }
}

College.java

import java.util.*;
public class College{
    //Implement the required business logic
    List<Feedback>feedbackList=new ArrayList<Feedback>();
    public void addFeedback(Feedback feedback)
    {
        feedbackList.add(feedback);
    }
    public List<Feedback>viewAllFeedbacks()
    {
        return feedbackList;
    }
    public List<Feedback>viewFeedbackbyCourse(String name)
    {
        List<Feedback> t1=new ArrayList<Feedback>();
        for(Feedback i:feedbackList)
        {
            if(i.getCourseName().equals(name))
            t1.add(i);
        }
        return t1;
    }
    public Feedback getHighestFeedback()
    {
        int m=feedbackList.get(0).getFeedbackRating();
        Feedback f=feedbackList.get(0);
        for(Feedback i:feedbackList)
        {
            if(i.getFeedbackRating()>m)
            {
                m=i.getFeedbackRating();
                f=i;
            }
        }
        return f;
    }
}

feedback.java

//Do not alter Feedback class
public class Feedback {
	private int feedbackId;
    private String courseName;
    private int facultyId;
    private int feedbackRating;
    public Feedback()
    {
    }
	public int getFeedbackId() {
		return feedbackId;
	}
	public void setFeedbackId(int feedbackId) {
		this.feedbackId = feedbackId;
	}
	public String getCourseName() {
		return courseName;
	}
	public void setCourseName(String courseName) {
		this.courseName = courseName;
	}
	public int getFacultyId() {
		return facultyId;
	}
	public void setFacultyId(int facultyId) {
		this.facultyId = facultyId;
	}
	public int getFeedbackRating() {
		return feedbackRating;
	}
	public void setFeedbackRating(int feedbackRating) {
		this.feedbackRating = feedbackRating;
	}
}
  1. Retrieve Student Info
  2. Member Manipulation
  3. PhoneBook Manipulation
  4. Count of Each Words
Sharing Is Caring

Leave a Comment