In this project, you’ll read in and manage hotel reviews from several reviewers. This will require you to create a two-dimensional array (reviewers x hotels) as well as parallel arrays to hold associated data. You’ll also implement a sorting algorithm which will require you not only to sort in the traditional way, but to maintain parallelism among data. There won’t be any exciting UI here, just some output of array data, and hotel/review data coming from a file.
2 Input File
2.1 File
The input file will contain the following elements, in order:
2.2 Example Contents
5 4
7 7 8 6 9
5 9 9 7 10
7 10 7 9 8
10 8 9 10 9
Grand Solmar Lands End Resort and Spa
Sandos Finisterra Los Cabos
Grand Fiesta Americana Los Cabos
Marina Fiesta Resort & Spa
RIU Santa Fe
The example file’s contents are interpreted as follows:
3 Concepts
3.1 Read the Data
You’ll need to read the file’s hotel review contents into an array called reviews. The hotel names will be in a parallel array called hotels, i.e., column 0 in reviews matches item 0 in the hotels array.
3.2 Create an Average Ranking Array
Now you’ll create an array to hold average rankings per hotel (avgRanks) and populate it. In this example, the first hotel would average (7+5+7+10+)/4 = 7.25, the second 8.5, the third 8.25, the fourth 8.0, and fifth 9.0. This means you now have three parallel arrays: reviews, hotels, and avgRanks.
3.3 Sort the Arrays by Average Ranking
You should sort tree arrays (reviews, hotels, and avgRanks). The hotel with the highest average ranking comes first and the one with the lowest ranking last. But remember to maintain parallel data as well; hotels and reviews need to move in lockstep with the ranked review data.
After sorting, you must get next result:
Array avgRanks
|
9 |
8.5 |
8.25 |
8 |
7.25 |
Array reviews
|
9 |
7 |
8 |
6 |
7 |
|
10 |
9 |
9 |
7 |
5 |
|
8 |
10 |
7 |
9 |
7 |
|
9 |
8 |
9 |
10 |
10 |
Array hotels
|
RIU Santa Fe |
|
Sandos Finisterra Los Cabos |
|
Grand Fiesta Americana Los Cabos |
|
Marina Fiesta Resort & Spa |
|
Grand Solmar Lands End Resort and Spa |
4 Class
Create a HotelReviews class and use it for this project. No other class-level data should be needed, other than the private data shown.
|
HotelReviews |
|
-hotels : Array of String |
|
-reviews : 2D Array of Integer |
|
-avgRanks : Array of Double |
|
Constructors |
|
+HotelReviews(File) |
|
Accessors |
|
+getHotelCount() : Integer |
|
+getRankHotel(review : Integer, hotel : Integer) : Integer |
|
+getHotel(index : Integer) : String |
|
+getAvgRank(index : Integer) : Double |
|
Private Methods |
|
-readData(File) |
|
-calculateAvgRankings() |
|
Other Methods |
|
+displayReviews() |
|
+displayAvgRanks() |
|
+displayHotels() |
|
+sortByRanking() |
|
+test() |
The constructor should only call methods readData and calculateAvgRankings (private methods).
5 Code Implementation
Create a main class which creates a new instance of the HotelReviews class, reads data from the file, and displays all arrays before and after sorting. See examples of output.
6 Testing
7 Submitting Your Work
Ranked Reviews
9 7 8 6 7
10 9 9 7 5
8 10 7 9 7
9 8 9 10 10
Hotels Rating
RIU Santa Fe 9.0
Sandos Finisterra Los Cabos 8.5
Grand Fiesta Americana Los Cabos 8.25
Marina Fiesta Resort & Spa 8.0
Grand Solmar Lands End Resort and Spa 7.25
Code
HotelReviews.java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class HotelReviews
{
private String []hotels;
private int [][]reviews;
private double []avgRanks;
public HotelReviews(File file)
{
readData(file);
calculateAvgRankings();
}
public int getHotelCount()
{
return hotels.length;
}
public String getHotel(int index)
{
return hotels[index];
}
public double getAvgRank(int index)
{
return avgRanks[index];
}
public int getRankHotel(int r,int h)
{
return reviews[r][h];
}
private void readData(File file)
{
int h,r;
String line;
String []values;
try
{
Scanner scanner = new Scanner(file);
line=scanner.nextLine();
values=line.split("\t");
h=Integer.parseInt(values[0]);
r=Integer.parseInt(values[1]);
reviews=new int[r][h];
hotels=new String[h];
avgRanks=new double[h];
for(int i=0;i<r;i++)
{
line=scanner.nextLine();
values=line.split("\t");
for(int j=0;j<h;j++)
{
reviews[i][j]=Integer.parseInt(values[j]);
}
}
for(int i=0;i<h;i++)
{
hotels[i]=scanner.nextLine();
}
scanner.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
}
private void calculateAvgRankings() {
for(int i=0;i<hotels.length;i++)
{
double sum=0;
for(int j=0;j<reviews.length;j++)
{
sum+=reviews[j][i];
}
avgRanks[i]=sum/reviews.length;
}
}
public void displayReviews()
{
for(int i=0;i<reviews.length;i++)
{
for(int j=0;j<reviews[i].length;j++)
{
System.out.print(reviews[i][j]+"\t");
}
System.out.println("");
}
}
public void displayAvgRanks()
{
for(int i=0;i<avgRanks.length;i++)
{
System.out.println(avgRanks[i]);
}
}
public void displayHotels()
{
for(int i=0;i<hotels.length;i++)
{
System.out.println(hotels[i]);
}
}
public void sortByRanking()
{
double temp;
String tempHotel;
for (int i = 0; i < hotels.length; i++)
{
for (int j = i + 1; j < hotels.length; j++)
{
if (avgRanks[i] < avgRanks[j])
{
temp = avgRanks[i];
avgRanks[i] = avgRanks[j];
avgRanks[j] = temp;
tempHotel=hotels[i];
hotels[i]=hotels[j];
hotels[j]=tempHotel;
}
}
}
}
}
Main.java that contains main method
import java.io.File;
public class Main
{
public static void main(String[] args)
{
File file=new File("review.txt");
HotelReviews review1=new HotelReviews(file);
System.out.println("\nBefore soting reviews are :");
review1.displayReviews();
System.out.println("\n\nHotels are: ");
review1.displayHotels();
System.out.println("\n\nHotels' average Rankigs are: ");
review1.displayAvgRanks();
review1.sortByRanking();
System.out.println("\n\nAfter soting reviews are :");
for(int i=0;i<review1.getHotelCount();i++)
{
System.out.printf("%-37s%10.2f%n",review1.getHotel(i),review1.getAvgRank(i));
}
System.out.println("\n\n");
}
}
output


review.txt file
If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.
In this project, you’ll read in and manage hotel reviews from several reviewers. This will require...
part one : Review Exercises 1. Write method called raggedCount that takes an integer n as argument and returns a ragged array of n rows of lengths 1, 2, 3, 4, ... , n and the whole array has the integers 1, 2, 3, 4, ... , n(n+1) 2 in row order. For example, raggedCount(4) should return the array: 1 2 3 4 5 6 7 8 9 10 1 2. Write a method called arrayConcat that takes as argument...
Write a program that will accept from the user a text file containing hurricane data along with an output filename. The data consists of the year, the number of storms, the number of hurricanes, and the damage in millions of US Dollars. The first line contains the word “Years” followed by the first year listed and the last year listed separated by tabs. The following lines contain the data separated by tabs. A sample text file is available in this...
Write a Java program, In this project, you are going to build a max-heap using array representation. In particular, your program should: • Implement two methods of building a max-heap. o Using sequential insertions (its time complexity: ?(?????), by successively applying the regular add method). o Using the optimal method (its time complexity: ?(?), the “smart” way we learned in class). For both methods, your implementations need to keep track of how many swaps (swapping parent and child) are required...
From: Java Programming: From Problem Analysis to Program Design, 5th ed. Ch. 9, page 636, Problem Exercise 12: Jason, Samantha, Ravi, Sheila, and Ankit are preparing for an upcoming marathon. Each day of the week they run certain miles and write them into a notebook. At the end of the week, they would like to know the number of miles run each day, the total miles for the week, and average miles run each day. Write a program to help...
I have a text file that this project needs to read from that has every possible combination of words but I am unsure how to do it. Also I'm pretty sure this program could use a program called "myArraylist" to sort through the text file but I am unsure how to implement this. I am unsure how to show the text file because it is massive, and I don't think it is possible to upload a text file to chegg....
Santa Monica College CS 20A: Data Structures with C++ Spring 2019 Name: True/False: Circle one Assignment 1 ID: 1. True / False 2. True / False 3. True / False 4. True / False 5. True / False 6. True / False 7. True / False 8. True / False 9. True / False 10. True / False Variable and functions identifiers can only begin with alphabet and digit. Compile time array sizes can be non-constant variables. Compile time array...
1. Implement a tostring() member function. This function will return a string representation of the LargeInteger. You should probably used string streams to implement this function. Note that the digits of the large integer are stored in reverse of their display order, e.g. the 1's place (100 ) is in index 0 of digits, the 10's place (101 ) is in index 1, etc. 2. Implement a second constructor for the LargeInteger. This constructor will be used to construct a...
IF YOU ZOOM IN ON THE PICTURES ON YOUR COMPUTER YOU
SHOULD BE ABLE TO SEE THEM.
The project is based on TripAdvisor content and reviews the goal
is to modify the code so that it uses sets to find out which
negative words were used throughout the whole 20 reviews
please adjust your code for the following changes --
The data file for this project (attached) contains 20 reviews
rather than 3 reviews
Each review occupies 13 lines rather...
Summary Write a program that demonstrates the skills you’ve learned throughout this quarter. This type of project offers only a few guidelines and requirements, allowing you to invest as much time, effort and imagination as you want. Submit your java programs (*.java) and any other I/O (*.txt) via Canvas You’ve worked quite hard to make it this far, so have a bit of fun with this project! Design Brief: Use Case Scenario You are hired to develop a...
These are my answere to the following questions: are they right? 1. B 2. T 3. T 4. T 5. F 6. T 7. A 8. D 9. E 10. B 11. B 12. A 13. A 14. D 15. C 16. D 17. T 18. C 19. T 20. T 21. T 22. A 23. T 24. D 25. B 26. A 27. A 28. A 29. T 30. C 31. D 32. A 33. T 34. F 35....