You are on page 1of 6

Báo cáo thực hành – Kỹ thuật lập trình nâng cao

Họ và tên: Đặng Nguyễn Phát Đạt

MSSV: 20200156

Lớp: 20DVT

Lab 2: THUỘC TÍNH


Bài 1:

namespace Lab2
{
class Program
{
static void Main(string[] args)
{
UserInformation user1 = new UserInformation("A", 16, 900);
Console.WriteLine(user1.ToString());
Console.ReadLine();
}
}
internal class UserInformation
{

private string userName;


public string UserName
{
get { return userName; }
set { userName = value; }
}
private int userAge;
public int UserAge
{
get { return userAge; }
set
{
if (value <= 18)
{
Console.WriteLine("Error! User’s age must be larger than 18");
}
else
userAge = value;
}
}
private uint userID;
public uint UserID
{
get { return userID; }
set
{
if (value >= 1000 && value <= 9999)

1
Báo cáo thực hành – Kỹ thuật lập trình nâng cao

{
userID = value;
}
else
Console.WriteLine("Error! ID must be between 1000 and 9999");
}
}
public UserInformation(string userName, int age, uint id)
{
UserName = userName;
UserAge = age;
UserID = id;
}

public override string ToString()


{
return $"Name: {UserName}, user ID: {UserID}, user Age: {UserAge}";

}
}

Bài 2

Code

2
Báo cáo thực hành – Kỹ thuật lập trình nâng cao

namespace Lab2
{
class Program
{
static void Main()
{
BankAccount user1 = new BankAccount("ale", 20, 1111, 1000, "123");

Console.WriteLine("Please enter your password:");


string password = Console.ReadLine();
bool isPasswordVerified = user1.VerifyPassword(password);

if (isPasswordVerified)
{

Console.WriteLine($"Your account balance is: {user1.Balance}");


}
else
{

Console.WriteLine("“Error! Access Denied");


}

Console.ReadKey();
}
}

class BankAccount
{
private string password;
private double balance;
private bool isPasswordVerified;
private UserInformation userInf;

public double Balance


{
get
{
if (isPasswordVerified)
{
return balance;
}
else
{
return 0;
}
}
set
{
if (isPasswordVerified)
{
balance = value;
}
}
}

public static double InterestRate { get; set; }

3
Báo cáo thực hành – Kỹ thuật lập trình nâng cao

public UserInformation UserInf { get; set; }

public BankAccount(string userName, int userAge, uint userID, double balance, string password)
{
userInf = new UserInformation(userName, userAge, userID);
this.password = password;
this.balance = balance;
isPasswordVerified = false;
}

public BankAccount(double interestRate)


{
InterestRate = 0.05;
}

public double CalculateInterestMoney()


{
return Balance * InterestRate;
}

public bool VerifyPassword(string password)


{
if (this.password == password)
{
isPasswordVerified = true;
return true;
}
else
{
isPasswordVerified = false;
return false;
}
}
}

internal class UserInformation


{
private string userName;
private int userAge;
private uint userID;

public string UserName


{
get { return userName; }
set { userName = value; }
}

public int UserAge


{
get { return userAge; }
set
{
if (value <= 18)
{
Console.WriteLine("Error! User’s age must be larger than 18");
}
else
{
userAge = value;

4
Báo cáo thực hành – Kỹ thuật lập trình nâng cao

}
}
}

public uint UserID


{
get { return userID; }
set
{
if (value >= 1000 && value <= 9999)
{
userID = value;
}
else
{
Console.WriteLine("Error! ID must be between 1000 and 9999");
}
}
}

public UserInformation(string userName, int age, uint id)


{
UserName = userName;
UserAge = age;

}
}
}

Hình ảnh chụp kết quả

5
Báo cáo thực hành – Kỹ thuật lập trình nâng cao

You might also like