Question
JAVA User deletion. Create two websites, each with at least three users (10% each website). Print all the initial data (10%). Delete two of the
JAVA
User deletion. Create two websites, each with at least three users (10% each website). Print all the initial data (10%). Delete two of the users in one website and one user in the other (10% each website). Print the new data and fix any problems you may encounter during deletion (10%).
public class User { private String name; private double dataAllowance; private String email;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public double getDataAllowance() { return dataAllowance; }
public void setDataAllowance(double dataAllowance) { this.dataAllowance = dataAllowance; }
public String getEmail() { return email; }
public void setEmail(String email) { this.email = email; } }
package websitesusers;
/** * */ public class Website { String name; User users[]; double extraData[]; int size; public Website(){ users = new User[5000]; extraData = new double[5000]; size = 0; //initially no users } //returns the index for a user object ... or -1 if not found in the array public int findIndex(User u){ for(int i = 0; i < size; i++) if(users[i] == u) return i; //if I reach this point, it means the loop checked all the elements of the array return -1; } //this works like a settter for user public void addUser(User u, double data){ users[size] = u; extraData[size] = data; size++; //one more user added, so size increases } //this also works like a setter public void removeUser(int index){ //do not want to do it... for(int i = index + 1; i < size; i++){ users[index - 1] = users[index]; extraData[index - 1] = extraData[index]; } size--; //one fewer user } public User getUser(int index){ return users[index]; }
//being a list, I need to get its size ... still part of getter for the user public int getUsersSize(){ return size; } //need to get the data for a user public double getExtraData(int index){ return extraData[index]; } //setter for data public void modifyExtraData(int index, double newData){ extraData[index] = newData; } public String getName() { return name; }
public void setName(String name) { this.name = name; } }
package websitesusers;
/** * * */ public class WebsitesUsers {
/** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started