SlideShare a Scribd company logo
Summary
HW6: Account Management
In HW4, you kept track of multiple usernames and its associated password using arrays.
However, usernames and passwords are typically part of a “User” object which in turn may be
part of an “Account” object. Accounts also typically require a certain level of security beyond
the typical encryption mechanisms. This assignment goes deeper into the concept of OOP as you
create objects that requires proper rules and scope for correct usage.
Aside: As with Item objects from HW5, Account and User data is typically stored in databases.
Skills Expected
? All the skills from previous Assignment(s)
? Accessors/Mutators
? Overriding methods: equals and toString
Assignment Description
You will write three Class objects and a Driver for each class (i.e. submit six .java files):
? User
? Account
? AccountList
Note: All properties MUST be private
Submission Requirement: The Driver Class
? Each Class designed MUST be submitted with a corresponding “Driver” Class
? The Driver Class should have a main() that demonstrates, at minimum
o Calling the appropriate constructor to create the appropriate instance
o Everyproperty(instancevariables)canbesetandgetcorrectly(whereallowed) ? Every public
method can be called successfully (and return the correct result)
Class Design: User
The User class is intended to be an abstract and simplified representation of a user
Class Properties
? First Name (String)
? Last Name (String)
? Username (String)
? Password (String)
Class Invariant
? First and Last Name must not be empty
? Username must be at least four characters long
? Password must be at least four characters long (is this a good invariant?)
Class Components
? A constructor that sets the initial user data (first name, last name, username, password)
? A getter/setter for each properties set out above
? A toString() method
? An equals() method
Class Design: Account
The Account class is intended to be an abstract and simplified representation of an account
Class Properties
? User (User)
? Balance (double) – represents how much money the user has in the account
Class Invariant
? Must be a valid account
? Balance must not be negative
Class Components
? A constructor that sets the initial User instance and balance amount
? A Getter but not a Setter for the each properties set out above (why?)
? A public method to add to the balance
? A public method to withdraw from the balance
? A toString() method
? An equals() method
Class Design: AccountList
The AccountList class is intended to be an abstract and simplified representation of a list of
accounts.
Class Properties
? Accounts (an array of Account objects – or ArrayList) o No getters or setters* (do you know
why?)
Class Invariant
? Can’t have multiple accounts with the same username
Class Components
? A public method that adds new accounts
? A public (boolean) method that determines whether an account with a given username exists in
the list
Grading Criteria
? User class object
o [2 points] Implements all required properties
? [2 points] Implements appropriate getters/setters
o [2points]Allinvariantsproperlyenforced
o [2points]Requiredclasscomponentsproperlyimplemented o
[2points]Driverclassrequirementsaremet
? Account class object
o [2 points] Implements all required properties
? [1 point] Implements appropriate getters
o [2 points] All invariants properly enforced
o [2points]Requiredclasscomponentsproperlyimplemented o
[2points]Driverclassrequirementsaremet
? AccountList class object
o [2 points] Implements all required properties
o [2 points] All invariants properly enforced
o [2points]Requiredclasscomponentsproperlyimplemented o
[2points]Driverclassrequirementsaremet
? [1 point] Method JavaDoc: description, @param, @return
? [1 Point] Descriptive variable names
? [1 Point] Appropriate class header comment block
output
User
account
accountlist Bluel: Terminal Window - HW6 Options toString: Name: Doe, John0 getUsername:
joe0 getPassword: 1234 Changing firstName to Jane Changing lastName to Dae Changing
username to jodie Changing password to supersecret toString: Name:Dae, Jane getUsername:
jodie getPas3word: supersecret Comparison with itself: true
Solution
public class User {
private String firstName;
private String lastName;
private String userName;
private String Password;
/**
* @param firstName
* @param lastName
* @param userName
* @param password
*/
public User(String firstName, String lastName, String userName,
String password) {
try {
setFirstName(firstName);
setLastName(lastName);
setUserName(userName);
setPassword(password);
} catch (NoSuchFieldException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* @return the firstName
*/
public String getFirstName() {
return firstName;
}
/**
* @param firstName
* the firstName to set
* @throws NoSuchFieldException
*/
public void setFirstName(String firstName) throws NoSuchFieldException {
if (firstName.length() == 0)
throw new NoSuchFieldException("first Name should not empty");
else
this.firstName = firstName;
}
/**
* @return the lastName
*/
public String getLastName() {
return lastName;
}
/**
* @param lastName
* the lastName to set
* @throws NoSuchFieldException
*/
public void setLastName(String lastName) throws NoSuchFieldException {
if (lastName.length() == 0)
throw new NoSuchFieldException("last Name should not empty");
else
this.lastName = lastName;
}
/**
* @return the userName
*/
public String getUserName() {
return userName;
}
/**
* @param userName
* the userName to set
* @throws NoSuchFieldException
*/
public void setUserName(String userName) throws NoSuchFieldException {
if (userName.length() < 4)
throw new NoSuchFieldException(
"user name should contain atleas 4 characters");
else
this.userName = userName;
}
/**
* @return the password
*/
public String getPassword() {
return Password;
}
/**
* @param password
* the password to set
* @throws NoSuchFieldException
*/
public void setPassword(String password) throws NoSuchFieldException {
if (password.length() < 4)
throw new NoSuchFieldException(
"password should contain atleas 4 characters");
else
this.Password = password;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((Password == null) ? 0 : Password.hashCode());
result = prime * result
+ ((firstName == null) ? 0 : firstName.hashCode());
result = prime * result
+ ((lastName == null) ? 0 : lastName.hashCode());
result = prime * result
+ ((userName == null) ? 0 : userName.hashCode());
return result;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
User other = (User) obj;
if (Password == null) {
if (other.Password != null)
return false;
} else if (!Password.equals(other.Password))
return false;
if (firstName == null) {
if (other.firstName != null)
return false;
} else if (!firstName.equals(other.firstName))
return false;
if (lastName == null) {
if (other.lastName != null)
return false;
} else if (!lastName.equals(other.lastName))
return false;
if (userName == null) {
if (other.userName != null)
return false;
} else if (!userName.equals(other.userName))
return false;
return true;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Name=" + firstName + ", " + lastName + ", userName=" + userName;
}
}
public class Account {
private User user;
private double balance;
/**
* @param user
* @param balance
*/
public Account(User user, double balance) {
try {
setUser(user);
setBalance(balance);
} catch (NoSuchFieldException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* @return the user
*/
public User getUser() {
return user;
}
/**
* @param user
* the user to set
*/
private void setUser(User user) {
this.user = user;
}
/**
* @return the balance
*/
public double getBalance() {
return balance;
}
/**
* @param balance
* the balance to set
* @throws NoSuchFieldException
*/
private void setBalance(double balance) throws NoSuchFieldException {
if (balance < 0)
throw new NoSuchFieldException("balance cannot be negative");
else
this.balance = balance;
}
/**
* @param amount
* @throws NoSuchFieldException
*/
public void diposit(double amount) throws NoSuchFieldException {
if (amount < 0)
throw new NoSuchFieldException("amount cannot be negative");
else
this.balance += amount;
}
/**
* @param amount
* @throws NoSuchFieldException
*/
public void withdraw(double amount) throws NoSuchFieldException {
if (amount < 0)
throw new NoSuchFieldException("amount cannot be negative");
else
this.balance -= amount;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(balance);
result = prime * result + (int) (temp ^ (temp >>> 32));
result = prime * result + ((user == null) ? 0 : user.hashCode());
return result;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Account other = (Account) obj;
if (Double.doubleToLongBits(balance) != Double
.doubleToLongBits(other.balance))
return false;
if (user == null) {
if (other.user != null)
return false;
} else if (!user.equals(other.user))
return false;
return true;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Account [user=" + user + ", balance=" + balance + "] ";
}
}
import java.util.ArrayList;
import java.util.List;
public class AccountList {
List accounts;
/**
*
*/
public AccountList() {
// TODO Auto-generated constructor stub
accounts = new ArrayList();
}
/**
* @param account
*/
public void addAccount(Account account) {
accounts.add(account);
}
/**
* @param username
* @return
*/
public boolean checkAccount(String username) {
for (int i = 0; i < accounts.size(); i++) {
if (accounts.get(i).getUser().getUserName().equals(username))
return true;
}
return false;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((accounts == null) ? 0 : accounts.hashCode());
return result;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
AccountList other = (AccountList) obj;
if (accounts == null) {
if (other.accounts != null)
return false;
} else if (!accounts.equals(other.accounts))
return false;
return true;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "AccountList [accounts=" + accounts + "]";
}
}
public class TestUser {
public static void main(String[] args) throws NoSuchFieldException {
User user1 = new User("John0", "Doe", "joe0", "1234");
System.out.println("getUserName:" + user1.getUserName());
System.out.println("getPassword:" + user1.getPassword());
System.out.println("changing firstname to Jane");
user1.setFirstName("Jane");
System.out.println("changing lastname to Dae");
user1.setFirstName("Dae");
System.out.println("changing username to jodie");
user1.setUserName("jodie");
System.out.println("changing password to supersecret");
user1.setPassword("supersecret");
System.out.println("getUserName:" + user1.getUserName());
System.out.println("getPassword:" + user1.getPassword());
System.out.println("Comparison with itself :" + user1.equals(user1));
}
}
OUTPUT 1 :
getUserName:joe0
getPassword:1234
changing firstname to Jane
changing lastname to Dae
changing username to jodie
changing password to supersecret
getUserName:jodie
getPassword:supersecret
Comparison with itself :true
public class TestAccount {
public static void main(String[] args) {
try {
User user1 = new User("John0", "Doe", "joe0", "1234");
Account account = new Account(user1, 100);
System.out.println("toString :" + account.toString());
System.out.println("getUser() toString :"
+ account.getUser().toString());
System.out.println("getBalance():" + account.getBalance());
System.out.println("Deposit 50");
account.diposit(50);
System.out.println("toString :" + account.toString());
System.out.println("withdraw 110");
account.withdraw(110);
System.out.println("toString :" + account.toString());
System.out.println("Comparison with itself :"
+ account.equals(account));
} catch (Exception e) {
// TODO: handle exception
}
}
}
OUTPUT 2:
toString :Account [user=Name=John0, Doe, userName=joe0, balance=100.0]
getUser() toString :Name=John0, Doe, userName=joe0
getBalance():100.0
Deposit 50
toString :Account [user=Name=John0, Doe, userName=joe0, balance=150.0]
withdraw 110
toString :Account [user=Name=John0, Doe, userName=joe0, balance=40.0]
Comparison with itself :true
public class TestAccountList {
public static void main(String[] args) {
AccountList accountList = new AccountList();
User user1 = new User("John0", "Doe", "joe0", "1234");
User user2 = new User("John1", "Doe", "joe0", "1234");
User user3 = new User("John2", "Doe", "joe0", "1234");
User user4 = new User("John3", "Doe", "joe0", "1234");
User user5 = new User("John4", "Doe", "joe0", "1234");
accountList.addAccount(new Account(user1, 100));
accountList.addAccount(new Account(user2, 200));
accountList.addAccount(new Account(user3, 300));
accountList.addAccount(new Account(user4, 400));
accountList.addAccount(new Account(user5, 500));
System.out.println(accountList);
System.out.println("Comparison with itself :"
+ accountList.equals(accountList));
}
}
OUTPUT 3:
AccountList [accounts=[Account [user=Name=John0, Doe, userName=joe0, balance=100.0]
, Account [user=Name=John1, Doe, userName=joe0, balance=200.0]
, Account [user=Name=John2, Doe, userName=joe0, balance=300.0]
, Account [user=Name=John3, Doe, userName=joe0, balance=400.0]
, Account [user=Name=John4, Doe, userName=joe0, balance=500.0]
]]
Comparison with itself :true

More Related Content

Similar to SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf

12-security.ppt - PHP and Arabic Language - Index
12-security.ppt - PHP and Arabic Language - Index12-security.ppt - PHP and Arabic Language - Index
12-security.ppt - PHP and Arabic Language - Indexwebhostingguy
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
Julie Iskander
 
Clean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionClean Code: Chapter 3 Function
Clean Code: Chapter 3 Function
Kent Huang
 
Clean code _v2003
 Clean code _v2003 Clean code _v2003
Clean code _v2003
R696
 
Java 17
Java 17Java 17
Java 17
Mutlu Okuducu
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
Jonathan Wage
 
Clean code
Clean codeClean code
Clean code
Arturo Herrero
 
Object Oriented Programming Basics with PHP
Object Oriented Programming Basics with PHPObject Oriented Programming Basics with PHP
Object Oriented Programming Basics with PHP
Daniel Kline
 
Unit testing zend framework apps
Unit testing zend framework appsUnit testing zend framework apps
Unit testing zend framework apps
Michelangelo van Dam
 
03 Object Relational Mapping
03 Object Relational Mapping03 Object Relational Mapping
03 Object Relational MappingRanjan Kumar
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial EnAnkur Dongre
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial EnAnkur Dongre
 
Micro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateMicro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateKiev ALT.NET
 
ADBMS ASSIGNMENT
ADBMS ASSIGNMENTADBMS ASSIGNMENT
ADBMS ASSIGNMENT
Lori Moore
 
Getting started with ES6
Getting started with ES6Getting started with ES6
Getting started with ES6
Nitay Neeman
 
Javascript
JavascriptJavascript
Javascript
D V BHASKAR REDDY
 
Lithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksLithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate Frameworks
Nate Abele
 

Similar to SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf (20)

12-security.ppt - PHP and Arabic Language - Index
12-security.ppt - PHP and Arabic Language - Index12-security.ppt - PHP and Arabic Language - Index
12-security.ppt - PHP and Arabic Language - Index
 
Security.ppt
Security.pptSecurity.ppt
Security.ppt
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
 
Clean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionClean Code: Chapter 3 Function
Clean Code: Chapter 3 Function
 
Clean code _v2003
 Clean code _v2003 Clean code _v2003
Clean code _v2003
 
Java 17
Java 17Java 17
Java 17
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
Clean code
Clean codeClean code
Clean code
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Framework
FrameworkFramework
Framework
 
Object Oriented Programming Basics with PHP
Object Oriented Programming Basics with PHPObject Oriented Programming Basics with PHP
Object Oriented Programming Basics with PHP
 
Unit testing zend framework apps
Unit testing zend framework appsUnit testing zend framework apps
Unit testing zend framework apps
 
03 Object Relational Mapping
03 Object Relational Mapping03 Object Relational Mapping
03 Object Relational Mapping
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 
Micro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateMicro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicate
 
ADBMS ASSIGNMENT
ADBMS ASSIGNMENTADBMS ASSIGNMENT
ADBMS ASSIGNMENT
 
Getting started with ES6
Getting started with ES6Getting started with ES6
Getting started with ES6
 
Javascript
JavascriptJavascript
Javascript
 
Lithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksLithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate Frameworks
 

More from ARORACOCKERY2111

Imagine a factorial design in which there are two factors. Each fact.pdf
Imagine a factorial design in which there are two factors. Each fact.pdfImagine a factorial design in which there are two factors. Each fact.pdf
Imagine a factorial design in which there are two factors. Each fact.pdf
ARORACOCKERY2111
 
How has technology impacted our societySolutionBy the followi.pdf
How has technology impacted our societySolutionBy the followi.pdfHow has technology impacted our societySolutionBy the followi.pdf
How has technology impacted our societySolutionBy the followi.pdf
ARORACOCKERY2111
 
How can you find DNA and RNA on a scene using spectroscopyHow c.pdf
How can you find DNA and RNA on a scene using spectroscopyHow c.pdfHow can you find DNA and RNA on a scene using spectroscopyHow c.pdf
How can you find DNA and RNA on a scene using spectroscopyHow c.pdf
ARORACOCKERY2111
 
Give definitions for comparative anatomy and embryology.Why do evo.pdf
Give definitions for comparative anatomy and embryology.Why do evo.pdfGive definitions for comparative anatomy and embryology.Why do evo.pdf
Give definitions for comparative anatomy and embryology.Why do evo.pdf
ARORACOCKERY2111
 
Find the area of the shaded region. The graph depicts the standard no.pdf
Find the area of the shaded region. The graph depicts the standard no.pdfFind the area of the shaded region. The graph depicts the standard no.pdf
Find the area of the shaded region. The graph depicts the standard no.pdf
ARORACOCKERY2111
 
Exercise 1. Comparative Anatomy Type of Circulatory outstanding Featu.pdf
Exercise 1. Comparative Anatomy Type of Circulatory outstanding Featu.pdfExercise 1. Comparative Anatomy Type of Circulatory outstanding Featu.pdf
Exercise 1. Comparative Anatomy Type of Circulatory outstanding Featu.pdf
ARORACOCKERY2111
 
Explain how the high heat capacity water that makes it a vital substa.pdf
Explain how the high heat capacity water that makes it a vital substa.pdfExplain how the high heat capacity water that makes it a vital substa.pdf
Explain how the high heat capacity water that makes it a vital substa.pdf
ARORACOCKERY2111
 
Discuss the characteristics that make something a protist as well as.pdf
Discuss the characteristics that make something a protist as well as.pdfDiscuss the characteristics that make something a protist as well as.pdf
Discuss the characteristics that make something a protist as well as.pdf
ARORACOCKERY2111
 
Describe the purpose for carrying out a DNAase Hypersensitivity assa.pdf
Describe the purpose for carrying out a DNAase Hypersensitivity assa.pdfDescribe the purpose for carrying out a DNAase Hypersensitivity assa.pdf
Describe the purpose for carrying out a DNAase Hypersensitivity assa.pdf
ARORACOCKERY2111
 
compare and contrast the morphology of Cestodes, Trematodes, and Nem.pdf
compare and contrast the morphology of Cestodes, Trematodes, and Nem.pdfcompare and contrast the morphology of Cestodes, Trematodes, and Nem.pdf
compare and contrast the morphology of Cestodes, Trematodes, and Nem.pdf
ARORACOCKERY2111
 
Carbon dioxide transport Drag each label to the appropriate location.pdf
Carbon dioxide transport  Drag each label to the appropriate location.pdfCarbon dioxide transport  Drag each label to the appropriate location.pdf
Carbon dioxide transport Drag each label to the appropriate location.pdf
ARORACOCKERY2111
 
An important part of electrical engineering is PCB design. One impor.pdf
An important part of electrical engineering is PCB design. One impor.pdfAn important part of electrical engineering is PCB design. One impor.pdf
An important part of electrical engineering is PCB design. One impor.pdf
ARORACOCKERY2111
 
Assume ND=NA=1E+15cm-3, in two different slabs of semiconductor (1 e.pdf
Assume ND=NA=1E+15cm-3, in two different slabs of semiconductor (1 e.pdfAssume ND=NA=1E+15cm-3, in two different slabs of semiconductor (1 e.pdf
Assume ND=NA=1E+15cm-3, in two different slabs of semiconductor (1 e.pdf
ARORACOCKERY2111
 
Alternate Electron acceptors Know what these electron acceptors will.pdf
Alternate Electron acceptors Know what these electron acceptors will.pdfAlternate Electron acceptors Know what these electron acceptors will.pdf
Alternate Electron acceptors Know what these electron acceptors will.pdf
ARORACOCKERY2111
 
A man with blood type A and a woman with blood type B have three chi.pdf
A man with blood type A and a woman with blood type B have three chi.pdfA man with blood type A and a woman with blood type B have three chi.pdf
A man with blood type A and a woman with blood type B have three chi.pdf
ARORACOCKERY2111
 
You have been exposed to each of the 8 microbes below.After a coup.pdf
You have been exposed to each of the 8 microbes below.After a coup.pdfYou have been exposed to each of the 8 microbes below.After a coup.pdf
You have been exposed to each of the 8 microbes below.After a coup.pdf
ARORACOCKERY2111
 
Which of the four levels of measurement is most appropriate for Wei.pdf
Which of the four levels of measurement is most appropriate for Wei.pdfWhich of the four levels of measurement is most appropriate for Wei.pdf
Which of the four levels of measurement is most appropriate for Wei.pdf
ARORACOCKERY2111
 
Which statement below regarding membrane structure and membrane tran.pdf
Which statement below regarding membrane structure and membrane tran.pdfWhich statement below regarding membrane structure and membrane tran.pdf
Which statement below regarding membrane structure and membrane tran.pdf
ARORACOCKERY2111
 
Why do cyanobacteria possess heterocystsA- Heterocysts shield the.pdf
Why do cyanobacteria possess heterocystsA- Heterocysts shield the.pdfWhy do cyanobacteria possess heterocystsA- Heterocysts shield the.pdf
Why do cyanobacteria possess heterocystsA- Heterocysts shield the.pdf
ARORACOCKERY2111
 
Which of the following isare true regarding hex digitsA. Hex dig.pdf
Which of the following isare true regarding hex digitsA. Hex dig.pdfWhich of the following isare true regarding hex digitsA. Hex dig.pdf
Which of the following isare true regarding hex digitsA. Hex dig.pdf
ARORACOCKERY2111
 

More from ARORACOCKERY2111 (20)

Imagine a factorial design in which there are two factors. Each fact.pdf
Imagine a factorial design in which there are two factors. Each fact.pdfImagine a factorial design in which there are two factors. Each fact.pdf
Imagine a factorial design in which there are two factors. Each fact.pdf
 
How has technology impacted our societySolutionBy the followi.pdf
How has technology impacted our societySolutionBy the followi.pdfHow has technology impacted our societySolutionBy the followi.pdf
How has technology impacted our societySolutionBy the followi.pdf
 
How can you find DNA and RNA on a scene using spectroscopyHow c.pdf
How can you find DNA and RNA on a scene using spectroscopyHow c.pdfHow can you find DNA and RNA on a scene using spectroscopyHow c.pdf
How can you find DNA and RNA on a scene using spectroscopyHow c.pdf
 
Give definitions for comparative anatomy and embryology.Why do evo.pdf
Give definitions for comparative anatomy and embryology.Why do evo.pdfGive definitions for comparative anatomy and embryology.Why do evo.pdf
Give definitions for comparative anatomy and embryology.Why do evo.pdf
 
Find the area of the shaded region. The graph depicts the standard no.pdf
Find the area of the shaded region. The graph depicts the standard no.pdfFind the area of the shaded region. The graph depicts the standard no.pdf
Find the area of the shaded region. The graph depicts the standard no.pdf
 
Exercise 1. Comparative Anatomy Type of Circulatory outstanding Featu.pdf
Exercise 1. Comparative Anatomy Type of Circulatory outstanding Featu.pdfExercise 1. Comparative Anatomy Type of Circulatory outstanding Featu.pdf
Exercise 1. Comparative Anatomy Type of Circulatory outstanding Featu.pdf
 
Explain how the high heat capacity water that makes it a vital substa.pdf
Explain how the high heat capacity water that makes it a vital substa.pdfExplain how the high heat capacity water that makes it a vital substa.pdf
Explain how the high heat capacity water that makes it a vital substa.pdf
 
Discuss the characteristics that make something a protist as well as.pdf
Discuss the characteristics that make something a protist as well as.pdfDiscuss the characteristics that make something a protist as well as.pdf
Discuss the characteristics that make something a protist as well as.pdf
 
Describe the purpose for carrying out a DNAase Hypersensitivity assa.pdf
Describe the purpose for carrying out a DNAase Hypersensitivity assa.pdfDescribe the purpose for carrying out a DNAase Hypersensitivity assa.pdf
Describe the purpose for carrying out a DNAase Hypersensitivity assa.pdf
 
compare and contrast the morphology of Cestodes, Trematodes, and Nem.pdf
compare and contrast the morphology of Cestodes, Trematodes, and Nem.pdfcompare and contrast the morphology of Cestodes, Trematodes, and Nem.pdf
compare and contrast the morphology of Cestodes, Trematodes, and Nem.pdf
 
Carbon dioxide transport Drag each label to the appropriate location.pdf
Carbon dioxide transport  Drag each label to the appropriate location.pdfCarbon dioxide transport  Drag each label to the appropriate location.pdf
Carbon dioxide transport Drag each label to the appropriate location.pdf
 
An important part of electrical engineering is PCB design. One impor.pdf
An important part of electrical engineering is PCB design. One impor.pdfAn important part of electrical engineering is PCB design. One impor.pdf
An important part of electrical engineering is PCB design. One impor.pdf
 
Assume ND=NA=1E+15cm-3, in two different slabs of semiconductor (1 e.pdf
Assume ND=NA=1E+15cm-3, in two different slabs of semiconductor (1 e.pdfAssume ND=NA=1E+15cm-3, in two different slabs of semiconductor (1 e.pdf
Assume ND=NA=1E+15cm-3, in two different slabs of semiconductor (1 e.pdf
 
Alternate Electron acceptors Know what these electron acceptors will.pdf
Alternate Electron acceptors Know what these electron acceptors will.pdfAlternate Electron acceptors Know what these electron acceptors will.pdf
Alternate Electron acceptors Know what these electron acceptors will.pdf
 
A man with blood type A and a woman with blood type B have three chi.pdf
A man with blood type A and a woman with blood type B have three chi.pdfA man with blood type A and a woman with blood type B have three chi.pdf
A man with blood type A and a woman with blood type B have three chi.pdf
 
You have been exposed to each of the 8 microbes below.After a coup.pdf
You have been exposed to each of the 8 microbes below.After a coup.pdfYou have been exposed to each of the 8 microbes below.After a coup.pdf
You have been exposed to each of the 8 microbes below.After a coup.pdf
 
Which of the four levels of measurement is most appropriate for Wei.pdf
Which of the four levels of measurement is most appropriate for Wei.pdfWhich of the four levels of measurement is most appropriate for Wei.pdf
Which of the four levels of measurement is most appropriate for Wei.pdf
 
Which statement below regarding membrane structure and membrane tran.pdf
Which statement below regarding membrane structure and membrane tran.pdfWhich statement below regarding membrane structure and membrane tran.pdf
Which statement below regarding membrane structure and membrane tran.pdf
 
Why do cyanobacteria possess heterocystsA- Heterocysts shield the.pdf
Why do cyanobacteria possess heterocystsA- Heterocysts shield the.pdfWhy do cyanobacteria possess heterocystsA- Heterocysts shield the.pdf
Why do cyanobacteria possess heterocystsA- Heterocysts shield the.pdf
 
Which of the following isare true regarding hex digitsA. Hex dig.pdf
Which of the following isare true regarding hex digitsA. Hex dig.pdfWhich of the following isare true regarding hex digitsA. Hex dig.pdf
Which of the following isare true regarding hex digitsA. Hex dig.pdf
 

Recently uploaded

Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 

Recently uploaded (20)

Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 

SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf

  • 1. Summary HW6: Account Management In HW4, you kept track of multiple usernames and its associated password using arrays. However, usernames and passwords are typically part of a “User” object which in turn may be part of an “Account” object. Accounts also typically require a certain level of security beyond the typical encryption mechanisms. This assignment goes deeper into the concept of OOP as you create objects that requires proper rules and scope for correct usage. Aside: As with Item objects from HW5, Account and User data is typically stored in databases. Skills Expected ? All the skills from previous Assignment(s) ? Accessors/Mutators ? Overriding methods: equals and toString Assignment Description You will write three Class objects and a Driver for each class (i.e. submit six .java files): ? User ? Account ? AccountList Note: All properties MUST be private Submission Requirement: The Driver Class ? Each Class designed MUST be submitted with a corresponding “Driver” Class ? The Driver Class should have a main() that demonstrates, at minimum o Calling the appropriate constructor to create the appropriate instance o Everyproperty(instancevariables)canbesetandgetcorrectly(whereallowed) ? Every public method can be called successfully (and return the correct result) Class Design: User The User class is intended to be an abstract and simplified representation of a user Class Properties ? First Name (String) ? Last Name (String) ? Username (String) ? Password (String) Class Invariant ? First and Last Name must not be empty ? Username must be at least four characters long ? Password must be at least four characters long (is this a good invariant?)
  • 2. Class Components ? A constructor that sets the initial user data (first name, last name, username, password) ? A getter/setter for each properties set out above ? A toString() method ? An equals() method Class Design: Account The Account class is intended to be an abstract and simplified representation of an account Class Properties ? User (User) ? Balance (double) – represents how much money the user has in the account Class Invariant ? Must be a valid account ? Balance must not be negative Class Components ? A constructor that sets the initial User instance and balance amount ? A Getter but not a Setter for the each properties set out above (why?) ? A public method to add to the balance ? A public method to withdraw from the balance ? A toString() method ? An equals() method Class Design: AccountList The AccountList class is intended to be an abstract and simplified representation of a list of accounts. Class Properties ? Accounts (an array of Account objects – or ArrayList) o No getters or setters* (do you know why?) Class Invariant ? Can’t have multiple accounts with the same username Class Components ? A public method that adds new accounts ? A public (boolean) method that determines whether an account with a given username exists in the list Grading Criteria ? User class object o [2 points] Implements all required properties ? [2 points] Implements appropriate getters/setters
  • 3. o [2points]Allinvariantsproperlyenforced o [2points]Requiredclasscomponentsproperlyimplemented o [2points]Driverclassrequirementsaremet ? Account class object o [2 points] Implements all required properties ? [1 point] Implements appropriate getters o [2 points] All invariants properly enforced o [2points]Requiredclasscomponentsproperlyimplemented o [2points]Driverclassrequirementsaremet ? AccountList class object o [2 points] Implements all required properties o [2 points] All invariants properly enforced o [2points]Requiredclasscomponentsproperlyimplemented o [2points]Driverclassrequirementsaremet ? [1 point] Method JavaDoc: description, @param, @return ? [1 Point] Descriptive variable names ? [1 Point] Appropriate class header comment block output User account accountlist Bluel: Terminal Window - HW6 Options toString: Name: Doe, John0 getUsername: joe0 getPassword: 1234 Changing firstName to Jane Changing lastName to Dae Changing username to jodie Changing password to supersecret toString: Name:Dae, Jane getUsername: jodie getPas3word: supersecret Comparison with itself: true Solution public class User { private String firstName; private String lastName; private String userName; private String Password; /** * @param firstName * @param lastName * @param userName
  • 4. * @param password */ public User(String firstName, String lastName, String userName, String password) { try { setFirstName(firstName); setLastName(lastName); setUserName(userName); setPassword(password); } catch (NoSuchFieldException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * @return the firstName */ public String getFirstName() { return firstName; } /** * @param firstName * the firstName to set * @throws NoSuchFieldException */ public void setFirstName(String firstName) throws NoSuchFieldException { if (firstName.length() == 0) throw new NoSuchFieldException("first Name should not empty"); else this.firstName = firstName; } /** * @return the lastName */ public String getLastName() { return lastName;
  • 5. } /** * @param lastName * the lastName to set * @throws NoSuchFieldException */ public void setLastName(String lastName) throws NoSuchFieldException { if (lastName.length() == 0) throw new NoSuchFieldException("last Name should not empty"); else this.lastName = lastName; } /** * @return the userName */ public String getUserName() { return userName; } /** * @param userName * the userName to set * @throws NoSuchFieldException */ public void setUserName(String userName) throws NoSuchFieldException { if (userName.length() < 4) throw new NoSuchFieldException( "user name should contain atleas 4 characters"); else this.userName = userName; } /** * @return the password */ public String getPassword() { return Password; }
  • 6. /** * @param password * the password to set * @throws NoSuchFieldException */ public void setPassword(String password) throws NoSuchFieldException { if (password.length() < 4) throw new NoSuchFieldException( "password should contain atleas 4 characters"); else this.Password = password; } /* * (non-Javadoc) * * @see java.lang.Object#hashCode() */ @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((Password == null) ? 0 : Password.hashCode()); result = prime * result + ((firstName == null) ? 0 : firstName.hashCode()); result = prime * result + ((lastName == null) ? 0 : lastName.hashCode()); result = prime * result + ((userName == null) ? 0 : userName.hashCode()); return result; } /* * (non-Javadoc) * * @see java.lang.Object#equals(java.lang.Object) */
  • 7. @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; User other = (User) obj; if (Password == null) { if (other.Password != null) return false; } else if (!Password.equals(other.Password)) return false; if (firstName == null) { if (other.firstName != null) return false; } else if (!firstName.equals(other.firstName)) return false; if (lastName == null) { if (other.lastName != null) return false; } else if (!lastName.equals(other.lastName)) return false; if (userName == null) { if (other.userName != null) return false; } else if (!userName.equals(other.userName)) return false; return true; } /* * (non-Javadoc) * * @see java.lang.Object#toString() */
  • 8. @Override public String toString() { return "Name=" + firstName + ", " + lastName + ", userName=" + userName; } } public class Account { private User user; private double balance; /** * @param user * @param balance */ public Account(User user, double balance) { try { setUser(user); setBalance(balance); } catch (NoSuchFieldException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * @return the user */ public User getUser() { return user; } /** * @param user * the user to set */ private void setUser(User user) { this.user = user; } /** * @return the balance
  • 9. */ public double getBalance() { return balance; } /** * @param balance * the balance to set * @throws NoSuchFieldException */ private void setBalance(double balance) throws NoSuchFieldException { if (balance < 0) throw new NoSuchFieldException("balance cannot be negative"); else this.balance = balance; } /** * @param amount * @throws NoSuchFieldException */ public void diposit(double amount) throws NoSuchFieldException { if (amount < 0) throw new NoSuchFieldException("amount cannot be negative"); else this.balance += amount; } /** * @param amount * @throws NoSuchFieldException */ public void withdraw(double amount) throws NoSuchFieldException { if (amount < 0) throw new NoSuchFieldException("amount cannot be negative"); else this.balance -= amount; } /*
  • 10. * (non-Javadoc) * * @see java.lang.Object#hashCode() */ @Override public int hashCode() { final int prime = 31; int result = 1; long temp; temp = Double.doubleToLongBits(balance); result = prime * result + (int) (temp ^ (temp >>> 32)); result = prime * result + ((user == null) ? 0 : user.hashCode()); return result; } /* * (non-Javadoc) * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Account other = (Account) obj; if (Double.doubleToLongBits(balance) != Double .doubleToLongBits(other.balance)) return false; if (user == null) { if (other.user != null) return false; } else if (!user.equals(other.user)) return false;
  • 11. return true; } /* * (non-Javadoc) * * @see java.lang.Object#toString() */ @Override public String toString() { return "Account [user=" + user + ", balance=" + balance + "] "; } } import java.util.ArrayList; import java.util.List; public class AccountList { List accounts; /** * */ public AccountList() { // TODO Auto-generated constructor stub accounts = new ArrayList(); } /** * @param account */ public void addAccount(Account account) { accounts.add(account); } /** * @param username * @return */ public boolean checkAccount(String username) { for (int i = 0; i < accounts.size(); i++) { if (accounts.get(i).getUser().getUserName().equals(username))
  • 12. return true; } return false; } /* * (non-Javadoc) * * @see java.lang.Object#hashCode() */ @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((accounts == null) ? 0 : accounts.hashCode()); return result; } /* * (non-Javadoc) * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; AccountList other = (AccountList) obj; if (accounts == null) { if (other.accounts != null) return false; } else if (!accounts.equals(other.accounts)) return false;
  • 13. return true; } /* * (non-Javadoc) * * @see java.lang.Object#toString() */ @Override public String toString() { return "AccountList [accounts=" + accounts + "]"; } } public class TestUser { public static void main(String[] args) throws NoSuchFieldException { User user1 = new User("John0", "Doe", "joe0", "1234"); System.out.println("getUserName:" + user1.getUserName()); System.out.println("getPassword:" + user1.getPassword()); System.out.println("changing firstname to Jane"); user1.setFirstName("Jane"); System.out.println("changing lastname to Dae"); user1.setFirstName("Dae"); System.out.println("changing username to jodie"); user1.setUserName("jodie"); System.out.println("changing password to supersecret"); user1.setPassword("supersecret"); System.out.println("getUserName:" + user1.getUserName()); System.out.println("getPassword:" + user1.getPassword()); System.out.println("Comparison with itself :" + user1.equals(user1)); } } OUTPUT 1 : getUserName:joe0 getPassword:1234 changing firstname to Jane changing lastname to Dae changing username to jodie
  • 14. changing password to supersecret getUserName:jodie getPassword:supersecret Comparison with itself :true public class TestAccount { public static void main(String[] args) { try { User user1 = new User("John0", "Doe", "joe0", "1234"); Account account = new Account(user1, 100); System.out.println("toString :" + account.toString()); System.out.println("getUser() toString :" + account.getUser().toString()); System.out.println("getBalance():" + account.getBalance()); System.out.println("Deposit 50"); account.diposit(50); System.out.println("toString :" + account.toString()); System.out.println("withdraw 110"); account.withdraw(110); System.out.println("toString :" + account.toString()); System.out.println("Comparison with itself :" + account.equals(account)); } catch (Exception e) { // TODO: handle exception } } } OUTPUT 2: toString :Account [user=Name=John0, Doe, userName=joe0, balance=100.0] getUser() toString :Name=John0, Doe, userName=joe0 getBalance():100.0 Deposit 50 toString :Account [user=Name=John0, Doe, userName=joe0, balance=150.0] withdraw 110 toString :Account [user=Name=John0, Doe, userName=joe0, balance=40.0] Comparison with itself :true
  • 15. public class TestAccountList { public static void main(String[] args) { AccountList accountList = new AccountList(); User user1 = new User("John0", "Doe", "joe0", "1234"); User user2 = new User("John1", "Doe", "joe0", "1234"); User user3 = new User("John2", "Doe", "joe0", "1234"); User user4 = new User("John3", "Doe", "joe0", "1234"); User user5 = new User("John4", "Doe", "joe0", "1234"); accountList.addAccount(new Account(user1, 100)); accountList.addAccount(new Account(user2, 200)); accountList.addAccount(new Account(user3, 300)); accountList.addAccount(new Account(user4, 400)); accountList.addAccount(new Account(user5, 500)); System.out.println(accountList); System.out.println("Comparison with itself :" + accountList.equals(accountList)); } } OUTPUT 3: AccountList [accounts=[Account [user=Name=John0, Doe, userName=joe0, balance=100.0] , Account [user=Name=John1, Doe, userName=joe0, balance=200.0] , Account [user=Name=John2, Doe, userName=joe0, balance=300.0] , Account [user=Name=John3, Doe, userName=joe0, balance=400.0] , Account [user=Name=John4, Doe, userName=joe0, balance=500.0] ]] Comparison with itself :true