Okay so for a school project I need to "remake twitter". So my question is... is there a way to create a new user every time I want to sign up. In my current program it will only create one user because I hard coded it, but I want it to be able to create a user without my hard coding it, so that I can have more than just one user.
edit: For clarification I want to be able to make a List of Users. How would I go about doing that.
import java.util.*;
public class MyClass {
public static void main(String args[]) {
// make it so u can log in to an existing account
// make it double check the password and email
Scanner sc = new Scanner(System.in);
int age;
System.out.println("-------------------------------------------------------------------------");
System.out.println("| Twitter |");
System.out.println("| Sign Up Log in |");
System.out.println("-------------------------------------------------------------------------");
System.out.println("Would you like to Log In or Sign Up?");
String responseString = sc.nextLine();
responseString = responseString.toUpperCase();
char responseSL = responseString.charAt(0);
if (responseSL == 'S') {
User user1 = new User(); //this creates the first user
System.out.println("Alright, lets get started by setting up your profile!");
System.out.println("Please enter a username.");
user1.setUserName(sc.nextLine());
System.out.println("Please enter your email address.");
user1.setEmailAddress(sc.nextLine());
System.out.println("Please enter a password.");
user1.setPassWord(sc.nextLine());
System.out.println("Alright we got your account all setup. Just take a moment to review everthing. Don't worry you can change this stuff later if you want!");
user1.printUserProfile();
} //end signup if
else {
// make sign in thing here.
} //end else
} //end main
} //end main class
class User {
// this class sets up the users profile when they are signing up
private String userName;
private String emailAddress;
private String passWord;
//Username, Age, Email Address, Tweets[ ]
//Methods
//Setters and getters, Create tweet
public User () {
}
public String getUserName() {return this.userName;}
public void setUserName(String userName) {this.userName = userName;}
public String getEmailAddress() {return this.emailAddress;}
public void setEmailAddress(String emailAddress) {this.emailAddress = emailAddress;}
public String getPassWord() {return this.passWord;}
public void setPassWord(String passWord) {this.passWord = passWord;}
public void printUserProfile() {
System.out.println("Username: " + this.userName);
System.out.println("Email Address: " + this.emailAddress);
System.out.println("Password (remember not to share this to anyone) " + this.passWord);
}
}
class Tweet {
private String tweet;
//Fields
//messageBody, hashtag, messageLength (less than 240 characters)
//Constructor
//Method containsHashtag
public Tweet () {
}
public String getTweet() {return this.tweet;}
public void setTweet(String tweet) {this.tweet = tweet;}
public static boolean checkHashTag(String tweet, String hashTag) {
String [] tweetArray = tweet.split(" ");
boolean hasHashTag = false;
for (int i = 0; i < tweetArray.length; i++) {
if (tweetArray[i].equals(hashTag)) {
hasHashTag = true;
}
}
return hasHashTag;
}
}