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

I need a help. Please fix my code. write a program that will read a text file co

ID: 3552104 • Letter: I

Question

I need a help. Please fix my code.
write a program that will read a text file containing names and will make an alphabetical list of all the names in that file. All names should be converted to upper case, and duplicates should be written to an output file selected by the user. Use a variable of type ArrayList<String> to store the words.
file: names
 Lavida Pedro Carla Jinyi Kasandra Miriam Anthea Lysanel Katherine Constance Alyssa Azvi Matthew Manuel Annmarisa Jaden Richard Luimer  Jaden Carla Pedro Katherine 
 
 I have done until this. 
 
 
import java.util.ArrayList;
import java.util.Scanner;
import java.io.IOException;
import java.io.File;

public class arraylist
{
public static void main(String[]args)throws IOException
{
File names = new File ("names.txt");
Scanner FileIn = new Scanner(names);
int[]n=new int[10];
ArrayList<String>name=new ArrayList<String>();
for(int i=0;i<20;i++)
{
name=FileIn.nextLine();
name=name.toUpperCase();
System.out.println(name);
}
I need a help. Please fix my code.
write a program that will read a text file containing names and will make an alphabetical list of all the names in that file. All names should be converted to upper case, and duplicates should be written to an output file selected by the user. Use a variable of type ArrayList<String> to store the words.
file: names
 Lavida Pedro Carla Jinyi Kasandra Miriam Anthea Lysanel Katherine Constance Alyssa Azvi Matthew Manuel Annmarisa Jaden Richard Luimer  Jaden Carla Pedro Katherine 
 
 I have done until this. 
 
 
import java.util.ArrayList;
import java.util.Scanner;
import java.io.IOException;
import java.io.File;

public class arraylist
{
public static void main(String[]args)throws IOException
{
File names = new File ("names.txt");
Scanner FileIn = new Scanner(names);
int[]n=new int[10];
ArrayList<String>name=new ArrayList<String>();
for(int i=0;i<20;i++)
{
name=FileIn.nextLine();
name=name.toUpperCase();
System.out.println(name);
}

Explanation / Answer


Code:


import java.util.ArrayList;

import java.util.Scanner;
import java.io.IOException;
import java.io.File;
import java.util.*;

public class arraylist
{
   public static void main(String[]args)throws IOException
   {
      File names = new File ("names.txt");
      Scanner FileIn = new Scanner(names);
      int[]n=new int[10];
      ArrayList<String>name=new ArrayList<String>();
      while(FileIn.hasNextLine())
      {
         String temp_name=FileIn.nextLine();
         temp_name=temp_name.toUpperCase();
         name.add(temp_name);
      }
      Collections.sort(name.subList(0, name.size()));
      for(int i =0;i<name.size();i++)
      System.out.println(name.get(i));
   }
  
}


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