Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program called ComputeARR to compute the average rating a restaurant is currently getting. The ratings are in sequences of stars, from 0 to

Write a program called ComputeARR to compute the average rating a restaurant is currently getting.

The ratings are in sequences of stars, from 0 to 8. Write the program so that it: Declares and creates a symbol table using the algs31.BinarySearchST class; Fills that symbol table with the following key-value pairs:

Key Value

******** 4

******* 3.5

****** 3

***** 2.5

**** 2

*** 1.5

** 1

* 0.5

1. Reads a sequence of star ratings from a file called a1ratings.txt using StdIn where the ratings are separated from each other by one or more whitespace characters.

2. Read these ratings by directing StdIn to the file with the fromFile method and then, to make reading in the strings easier, there is a method called StdIn.readAllStrings() that returns an array of Strings that automatically reads in all of the strings and divides them properly. Iterates through the array just filled using a for-each loop and accumulates a total score based on the ratings.

3. For each rating, look up its value in the symbol table and add it to the accumulator variable.

4. Computes and prints the average value.

5. Create your own test file called a1ratings.txt and place it in the data directory. Remember that your program will open it using the pathname data/a1grades.txt. Do not submit your test file.

PLEASE NOTE: Do not copy any code from the algs31.BinarySearchST class. You will have a single line in your program that declares and creates an empty symbol table and then you will need to call the instance methods put and get.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions