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

Can anyone help me with this program and please use the class with this program

ID: 3815874 • Letter: C

Question

Can anyone help me with this program and please use the class with this program , like class sting id; sting ...;
  

1. (40points) Write a Java program to create username. Your program must satisfy the following requirements:

All the usernames must be stored into text file (user.txt)

You have to use array structure in your program.

Username isn't case sensitive.

Username requires at least 4 characters and at most 8 characters

You can't create a username starting with a number.

You can't create a username starting with question mark `?`

You can’t create a username already in use.

Before you create a username, you should read all the usernames from the text file (user.txt), and store the username into an array. After this step, you should display all the usernames from the array (not directly from the text file).
In the case of failure to meet the requirement 4, 5, 6, and 7, you should display an appropriate warning message for each case and ask user to input a new ID. If a new username satisfied all the requirements, the username should be saved into the text file (user.txt). After saving the username, you have to read the text file, store the username into an array, and display a list of usernames once again. You are to introduce at least three methods other than main: for reading a file, for writing a file and for checking “inUse”.

Check Point and Deduction: (Please check this before submitting)

Check point

Deduction (points)

No Array or No data file reading/writing or No “at least three methods other than main”

40

No usernames display (at beginning)

10

No usernames display (after saving new to user.txt)

10

Requirement 4 (not work)

10

Requirement 4 (work but no warning message)

5

Requirement 5 (not work)

10

Requirement 5 (work but no warning message)

5

Requirement 6 (not work)

10

Requirement 6 (work but no warning message)

5

Requirement 7 (not work)

10

Requirement 7 (work but no warning message)

5

No comment (program head)

4

No comment (each method)

User.txt = bellevueCS210
Iloveyou

4

Check point

Deduction (points)

No Array or No data file reading/writing or No “at least three methods other than main”

40

No usernames display (at beginning)

10

No usernames display (after saving new to user.txt)

10

Requirement 4 (not work)

10

Requirement 4 (work but no warning message)

5

Requirement 5 (not work)

10

Requirement 5 (work but no warning message)

5

Requirement 6 (not work)

10

Requirement 6 (work but no warning message)

5

Requirement 7 (not work)

10

Requirement 7 (work but no warning message)

5

No comment (program head)

4

No comment (each method)

User.txt = bellevueCS210
Iloveyou

4

Project settings Toole Window Hep a stiwa import java io. import java util public class username public static string me new string 100 public static int howMany; public static void main (string args) throws while (true) Scanner console new Scanner (System.in Scanner input new Scanner (new File user txt howMany read File (input); 13 the end

Explanation / Answer

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class Username {
  
   public static String[] readUsername() throws IOException
   {
       List<String> users = new ArrayList<>();
       Scanner input = new Scanner(System.in);

File file = new File("users.txt");

input = new Scanner(file);


while (input.hasNextLine()) {
String line = input.nextLine();
users.add(line);
}
input.close();
String[] userArr = users.toArray(new String[0]);
return userArr;
   }
  
   public static void writeUsername(String userName) throws IOException
   {
       BufferedWriter bw = null;
       FileWriter fw = null;
       try {
           File file = new File("users.txt");

           // if file doesnt exists, then create it
           if (!file.exists()) {
               file.createNewFile();
           }
           // true = append file
           fw = new FileWriter(file.getAbsoluteFile(), true);
           bw = new BufferedWriter(fw);
           bw.write(" ");
           bw.write(userName);
       } catch (IOException e) {

           e.printStackTrace();

       } finally {
           try {
               if (bw != null)
                   bw.close();
               if (fw != null)
                   fw.close();
           } catch (IOException ex) {
               ex.printStackTrace();
           }
       }
   }

   public static boolean isInUse(String username, String[] users)
   {
       for (String user : users)
       {
           if (user.toUpperCase().equals(username.toUpperCase()))
           {
               return true;
           }
       }
       return false;
   }
  
   public static void main(String[] args) throws IOException
   {
       String[] users = readUsername();
       for (String user: users)
       {
           System.out.println(user);
       }
      
       Scanner sc = new Scanner(System.in);
       while(sc.hasNextLine())
       {
           String user = sc.nextLine();
           if (Character.isDigit(user.charAt(0)))
           {
               System.out.println("Please enter a username which doesn't start with number");
               continue;
           }
           if (user.charAt(0) == '?')
           {
               System.out.println("Please enter a username which doesn't start with ?");
               continue;
           }
           if (user.length() <= 4)
           {
               System.out.println("Please enter a username with atleast 4 chacter");
               continue;
           }
           if ( user.length()> 8)
           {
               System.out.println("Please enter a username with atmost 8 chacter");
               continue;
           }
           if (isInUse(user, users))
           {
               System.out.println("user name is already taken. Please try another");
               continue;
           }
           writeUsername(user);
           users = readUsername();
           for(String s: users)
           {
               System.out.println(s);
           }
       }
   }
}

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