This programing focuses on reading/writing file, on using array structures and s
ID: 3775005 • Letter: T
Question
This programing focuses on reading/writing file, on using array structures and string class. Be sure to include
Write a Java program to create username. The program must satisfy the following requirements:
1. All the usernames must be stored into text file (user.txt)
2. You have to use array structure in your program.
3. Username isn't case sensitive.
4. Username requires at least 6 characters
5. You can't create a username starting with a number.
6. You can't create a username starting with question mark `?`
7. 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”.
user.txt;
abcdefghIJ123
Iloveyou
Explanation / Answer
public class main {
public static void main(string[ ] args) {
WindowLogin.openWindow();
}
}
public class Database {
public static String[ ] userAdmin = { "abcsefghlj123", "iloveyou", "10" };
}
import javax.swing.*;
import java.awt.*;
public class WindowLogin {
public static void openwindow( ) {
JFrame f = new JFrame("Login");
JTextField userName = new JTextField(20);
JPasswordField password = new JPasswordField();
JPanel info = new JPanel(new GridLayout(2,1,5,5) );
JPanel lnpanel = new JPanel(new GridLayout(1,1,5,5) );
JButton lnButton = new JButton("Log in");
info.add(username);
info.add(password);
lnPanel.add9lnButton);
f.setLayout(new FlowLayout( ) );
f.setResizeable(false);
f.add(info);
f.add(lnpanel);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setVisible(true);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.