Ex 2
Ex 2
- Create a new folder that is named with the following format: studentID-studentname-
workshopNumber. The folder contains 4 projects: Q1,Q2,Q3,Q4,….
Example: se18123-nguyenvana-WS01 or SE12123-nguyen van a-WS01
- Use jdk 1.8
- The result must be formated like the given tesstcase
- Submit your result to the LMS page( example : se18123-nguyenvana-WS01.zip)
1. A class named “Account”. This class includes: String email, String password and some methods:
input(): to enters all fields from the keyboard
output(): to display information of the account object.
isValid(String m_email, String m_password): This function returns true if the given parameters equal
with an account object, vice versa, the function returns false.
changePassword(String newPassword): update the old pasword to the given parameter.
Validate: Password length is from 8 to 12 characters and Password only contains a..z, A..Z, 0-9
2. A class named “Tester”. It contains the main method and do some steps as the following:
public static void main(String[] args){
//create an account object using the operator “new”
// from the created object, call the input method
// from the created object, call the output method
// using the Scanner class to enter m_email,m_password
// from the created object, call the isValid method and display the result
// using the Scanner class to enter newPassword
// from the created object, call the changePassword ,call the output method to display the
result
}
TC1: TC3:
INPUT: INPUT:
enter email: [email protected] enter email: [email protected]
enter password: 12345 enter password: 12345
1. test input & output method 1. test input & output method
2. test invalid method 2. test invalid method
3. test changePassword method 3. test changePassword method
Enter option: 1 Enter option: 2
OUTPUT: OUTPUT:
[email protected] invalid
12345 TC4:
TC2: INPUT:
INPUT: enter email: [email protected]
enter email: [email protected] enter password: aA1234567
enter password: aA0101234 1. test input & output method
1. test input & output method 2. test invalid method
2. test invalid method 3. test changePassword method
3. test changePassword method Enter option: 3
Enter option: 2 enter new password: Abc1234567
OUTPUT: OUTPUT:
valid [email protected]
Abc1234567
Q2: Create a new project named “Q2”. Write a class Camel (in the default package of the NetBean) with
the following information:
Camel Where:
-desert:String Camel() - default constructor.
-step:int Camel(desert:String, step:int) - constructor, which
+Camel() sets values to desert and step.
+Camel(desert:String, step:int) getDesert():String – return desert in uppercase
+getDesert():String format.
+getStep():int getStep():int – return step.
+setStep(step:int):void
setStep(step:int):void – update step.
Create a class named Tester to test the program. In the main method, you write code to display the
result might look something like:
Q3: Create a new project named “Q3”. Write a class Account (in the default package of the NetBean)
with the following information:
Account Where:
-email:String Account (email:String, fullname:String,
-fullname:String isActive: boolean):constructor, which sets
-isActive:boolean values to email, fullname, and isActive.
+ Account(email:String, fullname:String, isActive: getFullname(): return the fullname in
boolean) uppercase format.
+ getFullname():String setIsActive(active : boolean): update
+ setIsActive(active : boolean):void isActive by the given parameter.
+ getIsActive():boolean
getIsActive ():return the isActive.
Create a class named “Tester” to test the program. In the main method, you need to code look like
2. Test setIsActive() and 2. Test setIsActive() and getIsActive() 2. Test setIsActive() and getIsActive()
getIsActive()
Enter option (1 or 2):2 Enter option (1 or 2):2
Enter option (1 or 2): 1
Enter true or false to set isActive:false Enter true or false to set isActive:true
OUTPUT:
MAI OUTPUT: OUTPUT:
false true
Q4: Create a new project named “Q4”. Write a class SavingAccount (in the default package of the
NetBean) with the following information:
SavingAccount Where:
SavingAccount
-accountID:String (accountID:String,balance:int):constructor, which
-balance:int sets values to accountID,balance
savingWithdraw(money:int): if the given money
+ SavingAccount(accountID:String, balance: int)
is the positive number and less then the balance
+ savingWithdraw(money: int):boolean then substract the money from the balance and
+ savingDeposit(money:int):boolean return true and else return false
+ getMoney():int
savingDeposit(money:int): if the given money is
the positive number then add the money to the
balance and return true and else return false.
getMoney(): return the balance
Create a class named “Tester” to test the program. In the main method, you need to code look like
Enter option (1 or 2): 1 Enter option (1 or 2): 1 Enter option (1 or 2): 2 Enter option (1 or 2): 2
Enter the money: 140 Enter the money: 30 Enter the money: 40 Enter the money: -20