Question

I am taking a Intro Java course in college and for that, I need to make...

I am taking a Intro Java course in college and for that, I need to make a Program to solve the following problem.

Our program is going to analyze the sentiment of the nintendo switch on Amazon by first gathering the positive percentage and the negative percentage of the product by looking at the customer reviews, and then display rather it is negative or positive based on the # of stars.

and my plans to solve the problem is down below,

  • Plan:

    • Identify keywords that make a review “negative”

    • Identify keywords that make a review “positive”

    • Create and array that has a case “if _____” review positive count ++

    • Keep count of positive vs negative words

    • If countPositive == countNegative Print out review is neutral

    • Else if countPositive > countNegative print out review is positive

    • Else review is negative

      • Use stars (1 to 5) to determine how negative and how positive. And display that as a percent.   Now How can I create a Program based on that, and succesfully run it? Thanks in advance.

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

Below is the code with comments doing the tasks you are planning to do  

import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.List;

public class Ratings {

    public static void main(String []args) {

        String feedback1 = "wordP1 wordN1 wordP1";
        String feedback2 = "wordN1 wordP1 wordN1";

        // prepare the list of all the positive words.
        List<String> positiveWords = Arrays.asList("wordP1");

        // similarly, prepare the list of all negative workds.
        List<String> negativeWords = Arrays.asList("wordN1");

        printReview(feedback1, positiveWords, negativeWords);
        printReview(feedback2, positiveWords, negativeWords);
    }

    /**
     * This method is responsible for printing the review.
     * @param feedback
     * @param positiveWords
     * @param negativeWords
     */
    private static void printReview(String feedback, List<String> positiveWords, List<String> negativeWords) {

        int positiveWordsCount = 0;
        int negativeWordsCount = 0;

        // split the feedback from space and gather it in an array.
        String [] feedbackWords = feedback.split(" ");

        // Now iterate over the feedback words to determine the count.
        for(String feedbackWord : feedbackWords) {
            if(positiveWords.contains(feedbackWord)) {
                positiveWordsCount ++;
            } else if(negativeWords.contains(feedbackWord)) {
                negativeWordsCount ++;
            }
        }

        // compute the overall feedback.
        double percentage = ((double )positiveWordsCount / (double)(positiveWordsCount + negativeWordsCount))*100;
        String review = null;
        
        // to make the percentage result to only 2 decimal places.
        DecimalFormat numberFormat = new DecimalFormat("#.00");

        if(positiveWordsCount == negativeWordsCount) {
            review = "Neutral";
        } else if(positiveWordsCount > negativeWordsCount) {
            review = "Positive";
        } else {
            review = "Negative";
            percentage = 100 - percentage;
        }

        System.out.println(review% + "  " + numberFormat.format(percentage));
    }
}

Sample Input1:

"wordP1 wordN1 wordP1"

Output:

66.67% Postive

Sample Input2:

wordN1 wordP1 wordN1

Output:

66.67% Negative

The screenshot with the sample inputs run are provided below.

Add a comment
Know the answer?
Add Answer to:
I am taking a Intro Java course in college and for that, I need to make...
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
  • I am currently taking a Foundation of Programming course where we are being taught Java. We...

    I am currently taking a Foundation of Programming course where we are being taught Java. We were shown how to make a program to calculate factorials recursively, how could I create an iterative method that could calculate factorials?

  • using Java program please copy and paste the code don't screenshot it import java.util.Scanner; import java.io.File;...

    using Java program please copy and paste the code don't screenshot it import java.util.Scanner; import java.io.File; public class { public static void main(String[] args) { // Create a new Scanner object to obtain // input from System.in // --> TODO // Ask user for a word to search for. Print // out a prompt // --> TODO // Use the Scanner object you created above to // take a word of input from the user. // --> TODO // ***...

  • Python program This assignment requires you to write a single large program. I have broken it...

    Python program This assignment requires you to write a single large program. I have broken it into two parts below as a suggestion for how to approach writing the code. Please turn in one program file. Sentiment Analysis is a Big Data problem which seeks to determine the general attitude of a writer given some text they have written. For instance, we would like to have a program that could look at the text "The film was a breath of...

  • In this assignment, you will explore more on text analysis and an elementary version of sentiment...

    In this assignment, you will explore more on text analysis and an elementary version of sentiment analysis. Sentiment analysis is the process of using a computer program to identify and categorise opinions in a piece of text in order to determine the writer’s attitude towards a particular topic (e.g., news, product, service etc.). The sentiment can be expressed as positive, negative or neutral. Create a Python file called a5.py that will perform text analysis on some text files. You can...

  • I am getting an error that the variable num was not declared in the scope on...

    I am getting an error that the variable num was not declared in the scope on the line of code that has; while(num != 5). Do you know how to fixe this error? #include <iostream> #include <iomanip> #include <string> #include<fstream> #include <cstring> using namespace std; //Declare the structure struct Games { string visit_team; int home_score; int visit_score; }; // Function prototypes int readData(Games *&stats); int menu(); void pickGame(Games *&stats, int size); void inputValid (Games *&stats, int size); void homeTotal(Games *&stats,...

  • I need help in Python. This is a two step problem So I have the code...

    I need help in Python. This is a two step problem So I have the code down, but I am missing some requirements that I am stuck on. Also, I need help verifying the problem is correct.:) 7. Random Number File Writer Write a program that writes a series of random numbers to a file. Each random number should be in the range of 1 through 500. The application should let the user specify how many random numbers the file...

  • I need help writing c++ code to make this program. 1. Define a function that can...

    I need help writing c++ code to make this program. 1. Define a function that can read the input file answers.dat. This function should not print anything. 2. Define a function that computes the quiz score of the function by comparing the correct answers to the student’s answer. The result should be a percentage between 0 and 100, not a value between 0 and 1. This function should not print anything. 3. Define a function that prints the report as...

  • I need trying to figure out how I can make create a code in Python with this exercise for I am having trouble doing so. Miles Per Gallon Calculator Write a GUI program that calculates a car's gas...

    I need trying to figure out how I can make create a code in Python with this exercise for I am having trouble doing so. Miles Per Gallon Calculator Write a GUI program that calculates a car's gas mileage. The program's window should have Entry widgets that let the user enter the number of gallons of gas the car holds, and the number of miles it can be driven on a full tank. When a Calculate MPG button is clicked,...

  • CS0007 Good day, I am in an entry-level Java class and need assistance completing an assignment....

    CS0007 Good day, I am in an entry-level Java class and need assistance completing an assignment. Below is the assignment criteria and the source code from the previous assignment to build from.  Any help would be appreciated, thank you in advance. Source Code from the previous assignment to build from shown below: Here we go! Let's start with me giving you some startup code: import java.io.*; import java.util.*; public class Project1 { // Random number generator. We will be using this...

  • I need help writing these 2 programs please include all the indents :) In this programming...

    I need help writing these 2 programs please include all the indents :) In this programming challenge you are to create two Python programs: randomwrite.py andrandomread.py. One program, randomwrite.py, is to write a set of random numbers to a file. The second program, randomread.py, is to read a set of random numbers from a file, counts how many were read, displays the random numbers, and displays the total count of random numbers. Random Number File Writer (randomwrite.py) Create a program...

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