Write the following in Java
Design a class called ReviewSystem, this class
should have an attribute reviewList, which is an ArrayList
type.
add a constructor to initialize the
attribute.
add a method addReviewAndComment(). This method
asks from the user to provide an integer (0 to 4 for the five ratings) and
a String as a comment. If the user inputs -1, it ends the loop of
asking. All valid user inputs should be saved to the
reviewList attribute. For example:
Type rating + comments. To end: -1 4 Great place! 4 Loved the food.
1 Pretty bad service. 3 New owners are nice. 0 Yuk!!! 2 What a gem.
-1
add a method displayComments(Rating rating).
This method displays all comments for a given rating to the
console.
add a method displayCommentsUp(Rating rating).
This method displays all comments for a given rating and all
comments for the ratings better than the given rating. for example,
displayCommentsUp(Rating.GOOD) should display all the
comments for ratings GOOD, BETTER, and BEST.
create a class ReviewSystemDriver, add a
main method to utilize the ReviewSystem class.
Enum
//ReviewSystemDriver.java
package reviewsystem;
public class ReviewSystemDriver {
public static void main(String args[]) {
ReviewSystem rs = new
ReviewSystem(); //initializing a reviewsystem object
rs.addReviewAndComment(); //to add
to reviewList
rs.displayComments("GOOD"); //searches for comments
with GOOD rating ONLY
rs.displayCommentsUp("GOOD");
//searches for comments with GOOD rating and ABOVE
}
}
//Rating.java
package reviewsystem;
public class Rating { //a class which stores a Rating
int star; //how many stars (0-4)
String comment; //What comment is given
String rating; //(WORST,WORSE,GOOD,BETTER,BEST)
according to the rating(0-4)
//getter setter methods for class variables
public String getRating() {
return rating;
}
public void setRating(String rating) {
this.rating = rating;
}
public int getStar() {
return star;
}
public void setStar(int star) {
this.star = star;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
}
//ReviewSystem.java
package reviewsystem;
import java.util.ArrayList;
import java.util.Scanner;
public class ReviewSystem {
ArrayList<Rating> reviewList = new
ArrayList<Rating>(); //list of Rating class
public void addReviewAndComment() { //prompts the user
to enter the star and comments
Scanner i = new Scanner(System.in);
//for taking integer input
Scanner s = new Scanner(System.in);
//for taking string input
System.out.println("Type rating +
comment. To end -1: ");
int put = 0;
while(put!=-1) {
Rating r = new
Rating(); //Rating class so that we can add it to the
ArrayList
put =
i.nextInt();
if(put == -1) {
//if user inputs -1
break;
}
r.setStar(put);
if(put == 4)
{
r.setRating("BEST"); //setting the Ratings
according to the stars
}
else if(put ==
3) {
r.setRating("BETTER");
}
else if(put ==
2) {
r.setRating("GOOD");
}
else if(put ==
1) {
r.setRating("WORSE");
}
else if(put
== 0) {
r.setRating("WORST");
}
else {
System.out.println("Some error occured try
again!(Rating: 0-4)"); //if invalid input then next loop
continue;
}
r.setComment(s.nextLine()); //takes the comment as input
reviewList.add(r); //adding the Rating object to the List
}
}
public void displayComments(String str) { //Displays
all comments with a particular Rating
for(int i = 0; i <
reviewList.size(); i++) {
if(reviewList.get(i).getRating().equals(str)) {
System.out.print("\nStars:
"+reviewList.get(i).getStar());
System.out.print("\nComment:
"+reviewList.get(i).getComment()+"\n");
}
}
}
public void displayCommentsUp(String str) { //displays
all comments equal and above a particular rating
int str_int = 0;
if(str.equals("WORST")) { // we set
the rating value to compare later
str_int =
0;
}
else if(str.equals("WORSE"))
{
str_int =
1;
}
else if(str.equals("GOOD")) {
str_int =
2;
}
else if(str.equals("BETTER"))
{
str_int =
3;
}
else if(str.equals("BEST"))
{
str_int =
4;
}
for(int i = 0; i <
reviewList.size(); i++) {
if(reviewList.get(i).getStar() >= str_int) {
System.out.print("\nStars:
"+reviewList.get(i).getStar());
System.out.print("\nComment:
"+reviewList.get(i).getComment()+"\n");
}
}
}
public void displayReview() { // to display the
arraylist
for(int i = 0; i<
reviewList.size(); i++) {
System.out.print("\nStars: "+reviewList.get(i).getStar());
System.out.print("\nComment:
"+reviewList.get(i).getComment()+"\n");
}
}
}
//ReviewSystemDriver.java
//Rating.java
//ReviewSystem.java
//OUTPUT
Write the following in Java Design a class called ReviewSystem, this class should have an attribute...
Write the following in Java Design an enum called Rating, it has the following names: bad, okay, good, better, best Design a class called Review (reviews might be for a restaurant, movie, etc), it has two attributes: a Rating type called rating, a String type called comment. Design getters and setters for the attributes. Override the toString() method to display both the rating and the comment.
I want to write a superclass with one private attribute and one method in JAVA The super class will later derive into 2 subclasses each with its own private attributes and each with a method that OVERRIDES the superclass method with each subclasses with one method ( that will do something) unique to that subclass. ALL classes must have constructors initializing its attributes and getter/setter methods. Then, in the main method, keep initializing objects of type superclasses based on user's...
You must write C# classes which are used to manage product review data for Books and Cars. You will write an abstract class called Review which abstracts common properties (review rating and comments). You will then create an Interface responsible for the functionality to display the Reviewcontent. Then, you will create 2 concrete classes which inherit from Review and implement the Interface. Finally, you will create console applicationwhich will create 2 CarReview instances and 2 BookReview instances and display them...
Write a Java class (name it TwoNumbers) that will manage two numbers. The class should have two integer variables. The class should have the following constructors: - TwoNumbers(); - TwoNumbers(3, 4); The first constructor should initialize the class variables to zero. The second constructor should initialize the class variables to the passed variables. The class should have the following methods: - setNumbers(3, 4); - setFirstNum(3); - setSecondNum(4); - getSum(); - getDiff(); - getProd(); The setNumbers(3, 4) method should initialize the...
In Java Create a class Worker. Your Worker class should include the following attributes as String variables: Name, Worker ID, Worker Address, Worker City, Worker State Create the constructor that initializes the above worker attributes. Then make another class name HourlyWorker that inherits from the Worker class. HourlyWOrker has to use the inherited parent class variables and add in hourlySalary and billableHours. Your HourlyWorker class should contain a constructor that calls the constructor from the Worker class to initialize the...
7.2 Write a Java program called to create an Excel spreadsheet Create a class called Food to represent a Lunch food item. Fields include name, calories, carbs In a main method (of a different class), ask the user "How many things are you going to eat for lunch?". Loop through each food item and prompt the user to enter the name, calories, and grams of carbs for that food item. Create a Food object with this data, and store each...
Create a java project and create Student class. This class should have the following attributes, name : String age : int id : String gender : String gpa : double and toString() method that returns the Student's detail. Your project should contain a TestStudent class where you get the student's info from user , create student's objects and save them in an arralist. You should save at least 10 student objects in this arraylist using loop statement. Then iterate through...
Design a JAVA class called Course. The class should contain: ○ The data fields courseName (String), numberOfStudents (int) and courseLecturer (String). ○ A constructor that constructs a Course object with the specified courseName, numberOfStudents and courseLecturer. ○ The relevant get and set methods for the data fields. ○ A toString() method that formats that returns a string that represents a course object in the following format: (courseName, courseLecturer, numberOfStudents) ● Create a new ArrayList called courses1, add 5 courses to...
JAVA Problem: Coffee do not use ArrayList or Case Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type, price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public void prepare ();...
The Tokenizer.java file should contain: A class called: Tokenizer Tokenizer should have a private variable that is an ArrayList of Token objects. Tokenizer should have a private variable that is an int, and keeps track of the number of keywords encountered when parsing through a files content. In this case there will only be one keyword: public. Tokenizer should have a default constructor that initializes the ArrayList of Token objects Tokenizer should have a public method called: tokenizeFile tokenizeFile should...