Answer To: DPIT121 – Lab Exercise 3 Due: Week 4 lab In lab 3, you will continue on another iteration for the...
Valupadasu answered on Mar 25 2021
Address.java
Address.java
public class Address {
private int streetNum;
private String street;
private String city;
public Address(int streetNum, String street, String city) {
this.streetNum = streetNum;
this.street = street;
this.city = city;
}
public int getStreetNum() {
return streetNum;
}
public void setStreetNum(int streetNum) {
this.streetNum = streetNum;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
@Override
public String toString() {
StringBuffer addrObj = new StringBuffer();
addrObj.append("Street No: ").append(getStreetNum()).append("\n")
.append("Street name: ").append(getStreet()).append("\n")
.append("City: ").append(city);
return addrObj.toString();
}
}
BusinessPlan.java
BusinessPlan.java
public class BusinessPlan extends MobilePlan{
int numberOfEmployees;
int ABN;
public BusinessPlan(String userName, int id, MobilePhone handset, int internetQuota, int capLimit,
int numberOfEmployees, int ABN) {
super(userName, id, handset, internetQuota, capLimit);
this.numberOfEmployees = numberOfEmployees;
this.ABN = ABN;
}
@Override
double calcPayment(int flatRate) {
double price = 0;
price += getHandset().getPrice()/24;
price += getCapLimit()/10;
price += getInternetQuota()*10;
price += flatRate;
if(this.numberOfEmployees > 10) {
price += (this.numberOfEmployees-10)*50;
}
return price;
}
@Override
public String toString() {
String str = "";
str += super.toString();
str += numberOfEmployees + " : " + ABN + "\n";
return str;
}
@Override
public void print() {
super.print();
System.out.println(numberOfEmployees + " : " + ABN + "\n");
}
}
MobileCompnay.java
MobileCompnay.java
import java.util.ArrayList;
public class MobileCompnay {
String name;
private ArrayList users = new ArrayList<>(); // list of all the users having a plan with the company
private String adminUsername;
private String adminPassword;
private int flatRate;
public MobileCompnay(String name, ArrayList users, String adminUsername, String adminPassword, int flatRate) {
this.name = name;
this.users = users;
this.adminUsername = adminUsername;
this.adminPassword = adminPassword;
this.flatRate = flatRate;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public ArrayList getUsers() {
return users;
}
public void setUsers(ArrayList users) {
this.users = users;
}
public String getAdminUsername() {
return adminUsername;
}
public void setAdminUsername(String adminUsername) {
this.adminUsername = adminUsername;
}
public String getAdminPassword() {
return adminPassword;
}
public void setAdminPassword(String adminPassword) {
this.adminPassword = adminPassword;
}
public int getFlatRate() {
return flatRate;
}
public void setFlatRate(int flatRate) {
this.flatRate = flatRate;
}
public boolean validateAdmin(String username, String password) {
return this.adminUsername.equals(username) && this.adminPassword.equals(password);
}
public boolean addUser(User user) {
if (findUser(user.getUserID()) != null) {
return false;
}
return getUsers().add(user);
}
public Boolean addUser(String name, int userID, Address address) {
return addUser(new User(name, userID, address));
}
public User findUser(int userID) {
for (User user : getUsers()) {
if (user.getUserID() == userID) {
return user;
}
}
return null;
}
public boolean addPlan (int userID, MobilePlan plan) {
User userObj = findUser(userID);
if(userObj == null) {
return false;
}
return userObj.addPlan(plan);
}
public MobilePlan findPlan (int userID ,int planID) {
User userObj = findUser(userID);
if(userObj == null) {
return null;
}
return userObj.findPlan(planID);
}
public void printPlans(int userID) {
User userObj = findUser(userID);
if(userObj != null) {
userObj.print();
}
}
public void print() {
for(User user : getUsers()) {
user.print();
user.printPlans(this.flatRate);
}
}
public String toString() {
StringBuffer output = new StringBuffer();
for(User user : getUsers()) {
output.append(user.toString()).append("\n");
}
return output.toString();
}
public boolean createPersonalPlan(int userID, String username, int id, MobilePhone mobilePhone, int internetQuota, int capLimit, MyDate expiryDate, String city ) {
User userObj = findUser(userID);
if(userObj == null) {
return false;
}
return userObj.createPersonalPlan(username, id, mobilePhone, internetQuota, capLimit, expiryDate, city);
}
public boolean createBusinessPlan( int userID, String username, int id, MobilePhone mobilePhone, int internetQuota, int capLimit, MyDate expiryDate, int numberOfEmployees , int ABN ){
User userObj = findUser(userID);
if(userObj == null) {
return false;
}
return userObj.createBusinessPlan(username, id, mobilePhone, internetQuota, capLimit, expiryDate, numberOfEmployees, ABN);
}
public double calcTotalPayments(int userID) {
User userObj = findUser(userID);
if(userObj == null) {
return 0.0;
}
return userObj.calcTotalPayments(this.flatRate);
}
public double calcTotalPayments () {
double totPayments = 0.0;
for(User user : getUsers()) {
totPayments += user.calcTotalPayments(this.flatRate);
}
return totPayments;
}
public boolean mobilePriceRise (int userID, double risePercent) {
User userObj = findUser(userID);
if(userObj == null) {
return false;
}
userObj.mobilePriceRiseAll(risePercent);
return true;
}
public void mobilePriceRise(double risePercent) {
for(User user : getUsers()) {
user.mobilePriceRiseAll(risePercent);
}
}
public ArrayList allPlans (){
ArrayList allPlans = new ArrayList<>();
for(User user : getUsers()) {
allPlans.addAll(user.getPlans());
}
return allPlans;
}
public ArrayList filterByMobileModel (int userID, String mobileModel){
User userObj = findUser(userID);
if(userObj == null) {
return null;
}
return userObj.filterByMobileModel(mobileModel);
}
public ArrayList filterByExpiryDate (int userID, MyDate date){
User userObj = findUser(userID);
if(userObj == null) {
return null;
}
return userObj.filterByExpiryDate(date);
}
public ArrayList filterByMobileModel (String mobileModel){
ArrayList allModelList = new ArrayList<>();
for(User user : getUsers()) {
allModelList.addAll(user.filterByMobileModel(mobileModel));
}
return allModelList;
}
public ArrayList filterByExpiryDate (MyDate date){
ArrayList planListByExpiryDate = new ArrayList<>();
for(User user : getUsers()) {
planListByExpiryDate.addAll(user.filterByExpiryDate(date));
}
return planListByExpiryDate;
}
}
MobilePhone.java
MobilePhone.java
public class MobilePhone {
private String model;
protected enum MobileType {Android, IOS, Windows};
private MobileType type;
public int memorySize;
private double price;
private MyDate expiryDate;
public MobilePhone(String model, int memorySize, double price, MobileType type) {
super();
this.model = model;
this.memorySize = memorySize;
this.price = price;
this.type = type;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public MobileType getType() {
return type;
}
public void setType(MobileType type) {
this.type = type;
}
public int getMemorySize() {
return memorySize;
}
public void setMemorySize(int memorySize) {
this.memorySize = memorySize;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public MyDate getExpiryDate() {
return exp...