Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need a code written in the java language and it has to meet the requirements a

ID: 3817608 • Letter: I

Question

I need a code written in the java language and it has to meet the requirements and rubric written below.

List of n favorites:

Knicks

Heat

Lakers

Celtics

Jazz

Requirements:

Decide on a list of n favorites (songs, bands, movies, video games, etc.) (between 5 and 10 favorites is fine).

Write a program that lists the n favorites but with a small twist.

Read in a file of n favorites (sample file in the Resources/Sample File area)...Please make your own.

Print a list of all n favorites to the user (so they know what is coming)

Ask if the user wishes to add or delete elements to/from the list.

If they wish to add an element, read in the element from the console

If they wish to remove an element, prompt for the item to be removed.

Print the next favorite from the list and for each favorite....

1st prompt for the user’s ranking of the favorite

2nd prompt for the user’s comments (for this round)

Slot the favorite into the final list using the supplied flowchart

Inform the user of the placement of the latest element.

After all n favorites, print the list to the screen

When complete, write back to the input file, adding the new comments to the previous rounds of comments.

The file should be able to be consumed by your program for the next round of play.


CONSOLE OUTPUT:
‘Favorite’ |   Rank | Comments from this round (plus all previous comments)

RUBRIC
  

Flowcharts are submitted and matches code - 5 Pts Each Flowchart + 5 pts for add/delete flowchart 20   **Create flowcharts for SP-A, SP-B, SP-C AND the add/remove element functionality** Program executes as submitted  - 4 points 4 A filename (or path) is stored into a variable and PROMINENTLY displayed at the TOP of the MAIN - 3 pts 3 N favorites listed sequentially from file - 5 points 5 User is prompted if they wish to add an element – 4 pts 4 User is prompted for the new element – 4 pts 4 New Element is used in the ranking game properly – 4 4 User is prompted if they wish to remove an element – 4 pts 4 User is prompted for the element to be removed – 4 pts 4 Removed element is not available for the ranking game – 4 pts 4 N sets of user input accepted sequentially  - 4 points 4 User is warned on out of range ranks or invalid input – 5 pts 5 User is notified of correct outcome of ranking – 10 points 5 Output List is generated after all favorites are ranked – 5 pts 5 Output list is correct, based on flowchart algorithm – 5 pt 5 Program writes back to the input file, adding any new elements and/or comments - 15 pts 15 Program terminates gracefully - 5 points 5 Source code is well documented - 5 points 5 Input & Output file (same file), can be used repeatedly, with additional comments added for each round of play – 10 pts

Explanation / Answer

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;


public class favorites
{
   static File FILENAME = new File("listofFavorites.txt");

public static void main(String[] args) throws IOException
{
     
   while(true)
   {
   System.out.println("Please provide number to perform operation");
   System.out.println("1:Print list of favorites");
   System.out.println("2:Add into list of favorites");
      System.out.println("3:Delete from the list");
   System.out.println("4:Exit");
   Scanner sc=new Scanner(System.in);
   int input=sc.nextInt();
   if(input==1)
   {
       readlist();
   }
   else if(input==2)
   {
       System.out.println("Enter Item");
       Scanner sc1=new Scanner(System.in);
   String item=sc1.next();
   addintolist(" "+item);
   }
   else if(input==3)
   {
       // File inputFile = new File("myFile.txt");
       File tempFile = new File("myTempFile.txt");

       BufferedReader reader = new BufferedReader(new FileReader(FILENAME));
       BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
           String lineToRemove = "";
       try (BufferedReader br = new BufferedReader(new FileReader(FILENAME))) {

           String sCurrentLine;
  
   //       while ((sCurrentLine = br.readLine()) != null) {
       //       System.out.println(sCurrentLine);
           String currentLine;
       while((currentLine = reader.readLine()) != null) {
           System.out.println(currentLine);
       String trimmedLine = currentLine.trim();
       if(trimmedLine.equals(lineToRemove)) continue;
       writer.write(currentLine + System.getProperty("line.separator"));
           System.out.println("want to remove (y/n)");
               Scanner sc2=new Scanner(System.in);
       String flag=sc2.next();
       if(flag.equalsIgnoreCase("y"))
           lineToRemove = currentLine;
      
           }

       } catch (IOException e) {
           e.printStackTrace();
       }
       writer.close();
       reader.close();
       boolean successful = tempFile.renameTo(FILENAME);
         
  

   }
   else if(input==4)
   {
       System.out.println("exiting from program");
       return;
   }
   else
   {
       System.out.println("invalid entry");
     
   }
   }
}
public static void readlist()
{
   try (BufferedReader br = new BufferedReader(new FileReader(FILENAME))) {

           String sCurrentLine;

           while ((sCurrentLine = br.readLine()) != null) {
               System.out.println(sCurrentLine);
           }

       } catch (IOException e) {
           e.printStackTrace();
       }
}

public static void addintolist(String item)
{
   try(FileWriter fw = new FileWriter(FILENAME, true);
           BufferedWriter bw = new BufferedWriter(fw);
           PrintWriter out = new PrintWriter(bw))
           {
          out.println(item);
           //more code
           //out.println("more text");
           //more code
           } catch (IOException e) {
           //exception handling left as an exercise for the reader
           }
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote