Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA B. Website modification. Create two websites, each with at least three users (20% each website). After those are created, print out all their information

JAVA

B. Website modification. Create two websites, each with at least three users (20% each website). After those are created, print out all their information to make sure the creation process works well. Fix any problems you may encounter (20%).

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions