Question

In this project, you’ll read in and manage hotel reviews from several reviewers. This will require...

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:

  • On the first line, an integer indicating how many hotels were reviewed (h), followed by an integer indicating how many reviewers have provided data (r).
  • On the next r lines, a sequence of h integers, each a review score in the range 1 to 10.
  • Once the review data is finished, the following h lines will contain the hotels titles.
  • Data elements are tokenized (separated by space (or spaces), tabs, etc.

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:

  • Four reviewers participated, reviewing five hotels.
  • The first reviewer gave the first hotel “7”, the second hotel “7”, and the third “8” and so on. Next reviewers scores follow in similar fashion.
  • The five hotels reviewed are titled “Grand Solmar Lands End Resort and Spa,” “Sandos Finisterra Los Cabos,” “Grand Fiesta Americana Los Cabos,” “Marina Fiesta Resort & Spa,” and “RIU Santa Fe” respectively.

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

  • Write test methods for each of your methods. You don’t need to test the display* methods.
  • Test with different numbers of hotels and reviewers to make sure your algorithms are correct.
  • Manual inspection will be necessary; the debugger is your friend and will be very useful here.

7       Submitting Your Work

  • Submit your .jar or .zip file
  • If your test method relies on test files, be sure and include them in your submission.

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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.

Add a comment
Know the answer?
Add Answer to:
In this project, you’ll read in and manage hotel reviews from several reviewers. This will require...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • part one : Review Exercises 1. Write method called raggedCount that takes an integer n as...

    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...

    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...

    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...

    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...

  • Santa Monica College CS 20A: Data Structures with C++ Spring 2019 Name: True/False: Circle one Assignment...

    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...

  • IF YOU ZOOM IN ON THE PICTURES ON YOUR COMPUTER YOU SHOULD BE ABLE TO SEE...

    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...

    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....

    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....

  • Group Project 1 The Micro-1 Processor Simulation <Micro-1 Computer> Here's the organization of a computer equipped...

    Group Project 1 The Micro-1 Processor Simulation <Micro-1 Computer> Here's the organization of a computer equipped with a Micro-1 processor Memory contains an array of integer cells: int cell[] = new int[CAP]; where CAP is the capacity of memory. Initially this is set to 256. Internally, the Micro-1 processor is equipped with eight 32-bit data/address registers and two 32 bit control registers: PC, the program counter, contains the address of the next instruction to execute. IR, the instruction register, contains...

  • Using Doubly Linked List, and Sorting methods: (In Java) (please attach your output with the answer)...

    Using Doubly Linked List, and Sorting methods: (In Java) (please attach your output with the answer) (Please answer if it is correct and working) (Have been getting many wrong and spam answers lately) Introduction: In this project, we use the same file structure of Artist and Art to extend the concepts of array and linked list and have them applied to sorting. The input files of p1arts.txt and p1artists.txt have been slightly modified. They are named p7arts.txt and p7artists.txt. Assignments:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT