Đề Thi PE SWT301 - FA 2024 - PE1

  • Bắt đầu Bắt đầu HongThao85
  • Ngày bắt đầu Ngày bắt đầu
  • Trả lời Trả lời 11
  • Xem Xem 5K
  • Thẻ Thẻ
    swt301
Campus
Hà Nội
Học kỳ
FALL2024
Loại tài liệu
PE

HongThao85

FPT Student
Tham gia
22/7/23
Bài viết
0
FUO Point
1,245
SWT301 - FA 2024 - PE1
12/11/2024 12h50
 

Đính kèm

  • SWT301_-_FA_2024_-_PE1_2961.webp
    SWT301_-_FA_2024_-_PE1_2961.webp
    48.5 KB · Xem: 2,780
  • SWT301_-_FA_2024_-_PE1_2961.webp
    SWT301_-_FA_2024_-_PE1_2961.webp
    182.3 KB · Xem: 2,609
  • SWT301_-_FA_2024_-_PE1_2961.webp
    SWT301_-_FA_2024_-_PE1_2961.webp
    173.6 KB · Xem: 2,465
  • SWT301_-_FA_2024_-_PE1_2961.webp
    SWT301_-_FA_2024_-_PE1_2961.webp
    132.7 KB · Xem: 2,555
  • SWT301_-_FA_2024_-_PE1_2961.webp
    SWT301_-_FA_2024_-_PE1_2961.webp
    228.5 KB · Xem: 2,224
  • SWT301_-_FA_2024_-_PE1_2961.webp
    SWT301_-_FA_2024_-_PE1_2961.webp
    125.5 KB · Xem: 2,134
  • SWT301_-_FA_2024_-_PE1_2961.webp
    SWT301_-_FA_2024_-_PE1_2961.webp
    131.9 KB · Xem: 2,065
  • SWT301_-_FA_2024_-_PE1_2961.webp
    SWT301_-_FA_2024_-_PE1_2961.webp
    198.1 KB · Xem: 1,722
  • SWT301_-_FA_2024_-_PE1_2961.webp
    SWT301_-_FA_2024_-_PE1_2961.webp
    160.3 KB · Xem: 1,479
  • SWT301_-_FA_2024_-_PE1_2961.webp
    SWT301_-_FA_2024_-_PE1_2961.webp
    155.3 KB · Xem: 2,499
  • Solution.rar
    Solution.rar
    17.7 KB · Xem: 721
  • Defect ID: DF01.
    Defect Name: Cannot find symbol ‘BufferedReader’.
    Line of Code: 2.
    Defect Description: Missing import ‘java.io.BufferedReader’.
    Fixing Solution: Add ‘import java.io.BufferedReader;’ at the beginning of file
  • Defect ID: DF02
    Defect Name: Cannot find symbol IOException
    Line of Code: 10
    Defect Description: Missing import ‘java.io.IOException’
    Fixing Solution: Add ‘import java.io.IOException;’ at the beginning of file
  • Defect ID: DF03
    Defect Name: Cannot find symbol IOException
    Line of Code: 20
    Defect Description: Missing import ‘java.io.IOException’
    Fixing Solution: Add ‘import java.io.IOException;’ at the beginning of file
  • Defect ID: DF04
    Defect Name: Wrong logic in condition.
    Line of code: 7
    Defect Description: The condition is incorrect at the operator or and filePath.isEmpty(). File cannot be opened successfully is the file path is empty, and the operator or will create conflict in the condition logic.
    Fixing Solution: Modify the condition into “filePath!=null && !filePath.isEmpty()).
  • Defect ID: DF05
    Defect Name: Wrong Naming Convention of Class Name.
    Line of Code:1
    Description: The Name of class “fileProcess” doesn’t match the right naming Convention of a java class name. The first letter of the class name is lower case which is not correct.
    Fixing Solution: Change the name of the class into “FileProcessor”.
  • Defect ID: DF06
    Defect Name: Wrong Naming Convention of field Name.
    Line of Code: 3
    Description: The Name of the field “FilePath” doesn’t match the right naming Convention of a java field name. The first letter of the class name is upper case which is not correct.
    Fixing Solution: Change the field name into “filePath”
  • Defect ID: DF07
    Defect Name: The variable ‘reader’ is never initialized
    Line of Code: 2
    Defect Description: The variable ‘writer’ is not initialized before being used at line 17, 23.
    Fixing Solution: Initialize variable ‘reader’ at line 2
  • Defect ID: DF08
    Defect Name: The variable ‘FilePath’ is never initialized
    Line of Code: 3
    Defect Description: The variable ‘writer’ is not initialized before being used at line 27
    Fixing Solution: Initialize variable ‘filePath’ at line 3.
  • Defect ID: DF08
    Defect Name: Unreachable code
    Line of Code: 33
    Defect Description: The condition FilePath == null is always return true because the variable is never initialized. Thus, the readFile() function will never be reached.
    Fixing Solution: Initialize variable ‘filePath’ at line 3.
 
Q2:
Java:
//Invalid partitioning
@Test(expected = IllegalArgumentException.class)
public void testNoItemsOrder(){
OrderCalculator calculator= new OrderCalculator();
calculator.calculateTotalPrice(new double[]{},"VIP",false,null);
}



@Test(expected = IllegalArgumentException.class)
public void testInvalidPrice(){
OrderCalculator calculator= new OrderCalculator();
calculator.calculateTotalPrice(new double[]{-100},"VIP",false,null);
}
@Test(expected = IllegalArgumentException.class)
public void testNullOrder(){
OrderCalculator calculator= new OrderCalculator();
calculator.calculateTotalPrice(null,"VIP",false,null);
}





//Valid partitioning
[USER=18840]@Test[/USER]
//VIP CUSTOMER
public void testVIPCustomerWithNoDiscountCode(){
OrderCalculator calculator= new OrderCalculator();
double total = calculator.calculateTotalPrice(new double[]{100,200},"VIP",true,null);
assertEquals(240.0,total,0.01);
}


[USER=18840]@Test[/USER]
public void testRegularCustomerWithNoDiscountCode(){
OrderCalculator calculator= new OrderCalculator();
double[] items= {50.0,50.0};
String customerType= "Regular";
boolean isVip= false;
String discountCode = null;
double expect= 100.0;
double total = calculator.calculateTotalPrice(items,customerType,isVip,discountCode);
assertEquals(95,total,0.01);
}
[USER=18840]@Test[/USER]
public void testNoCustomerTpeWithNoDiscountCode(){
OrderCalculator calculator= new OrderCalculator();
double[] items= {50.0,50.0};
String customerType= "";
boolean isVip= false;
String discountCode = null;
double expect= 100;
double total = calculator.calculateTotalPrice(items,customerType,isVip,discountCode);
assertEquals(expect,total,0.01);
}

[USER=18840]@Test[/USER]
public void testPriceWithEmptyDiscountCode(){
OrderCalculator calculator= new OrderCalculator();
double[] items= {50.0,50.0};
String customerType= "";
boolean isVip= true;
String discountCode = "";

double expect= 80;
double total = calculator.calculateTotalPrice(items,customerType,isVip,discountCode);
assertEquals(expect,total,0.01);
}
[USER=18840]@Test[/USER]
public void testPriceWithWrongDiscountCode(){
OrderCalculator calculator= new OrderCalculator();
double[] items= {50.0,50.0};
String customerType= "";
boolean isVip= true;
String discountCode = "ABC";

double expect= 80;
double total = calculator.calculateTotalPrice(items,customerType,isVip,discountCode);
assertEquals(expect,total,0.01);
}
[USER=18840]@Test[/USER]
public void testVipCustomerWithSALE10(){
OrderCalculator calculator= new OrderCalculator();
double[] items= {50.0,50.0};
String customerType= "";
boolean isVip= true;
String discountCode = "SALE10";

double expect= 70;
double total = calculator.calculateTotalPrice(items,customerType,isVip,discountCode);
assertEquals(expect,total,0.01);
}
[USER=18840]@Test[/USER]
public void testVipCustomerWithWelcomes(){
OrderCalculator calculator= new OrderCalculator();
double[] items= {50.0,50.0};
String customerType= "";
boolean isVip= true;
String discountCode = "WELCOMES";

double expect= 100.0;
double total = calculator.calculateTotalPrice(items,customerType,isVip,discountCode);
assertEquals(75,total,0.01);
}
[USER=18840]@Test[/USER]
public void testRegularCustomerWithSale10(){
OrderCalculator calculator= new OrderCalculator();
double[] items= {50.0,50.0};
String customerType= "Regular";
boolean isVip= false;
String discountCode = "SALE10";

double expect= 85;
double total = calculator.calculateTotalPrice(items,customerType,isVip,discountCode);
assertEquals(expect,total,0.01);
}
[USER=18840]@Test[/USER]
public void testRegularCustomerWithWelcomes(){
OrderCalculator calculator= new OrderCalculator();
double[] items= {50.0,50.0};
String customerType= "Regular";
boolean isVip= false;
String discountCode = "WELCOMES";
double expect= 90;
double total = calculator.calculateTotalPrice(items,customerType,isVip,discountCode);
assertEquals(expect,total,0.01);
}
[USER=18840]@Test[/USER]
public void testNoTypeCustomerWithSale10(){
OrderCalculator calculator= new OrderCalculator();
double[] items= {50.0,50.0};
String customerType= "";
boolean isVip= false;
String discountCode = "SALE10";

double expect= 90;
double total = calculator.calculateTotalPrice(items,customerType,isVip,discountCode);
assertEquals(expect,total,0.01);
}
[USER=18840]@Test[/USER]
public void testNoTypeCustomerWithWelcome(){
OrderCalculator calculator= new OrderCalculator();
double[] items= {50.0,50.0};
String customerType= "";
boolean isVip= false;
String discountCode = "WELCOMES";

double expect= 95;
double total = calculator.calculateTotalPrice(items,customerType,isVip,discountCode);
assertEquals(expect,total,0.01);
}
}
 
Chỉnh sửa lần cuối bởi người điều hành:
bài làm 9.5đ cho ae tham khảo
cách setup và làm bài câu 2:

1. tạo sẵn 1 project = maven (ưu tiên dùng intellij vì nó gợi ý ngon) và cài sẵn dependency junit
2. Tạo 1 class mới copy toàn bộ code từ câu 2
3. Viết 1 class khác và copy code test mẫu đề cho (nếu không biết cách truyền input ntn thì code mẫu có chỉ cách truyền input)
4. Làm bài
 
cách setup và làm bài câu 2:

1. tạo sẵn 1 project = maven (ưu tiên dùng intellij vì nó gợi ý ngon) và cài sẵn dependency junit
2. Tạo 1 class mới copy toàn bộ code từ câu 2
3. Viết 1 class khác và copy code test mẫu đề cho (nếu không biết cách truyền input ntn thì code mẫu có chỉ cách truyền input)
4. Làm bài
dạ cho em hỏi mình code luôn bănq word sẽ có những rủi ro gì không ạ
 
Q2:
Java:
//Invalid partitioning
@Test(expected = IllegalArgumentException.class)
public void testNoItemsOrder(){
OrderCalculator calculator= new OrderCalculator();
calculator.calculateTotalPrice(new double[]{},"VIP",false,null);
}



@Test(expected = IllegalArgumentException.class)
public void testInvalidPrice(){
OrderCalculator calculator= new OrderCalculator();
calculator.calculateTotalPrice(new double[]{-100},"VIP",false,null);
}
@Test(expected = IllegalArgumentException.class)
public void testNullOrder(){
OrderCalculator calculator= new OrderCalculator();
calculator.calculateTotalPrice(null,"VIP",false,null);
}





//Valid partitioning
[USER=18840]@Test[/USER]
//VIP CUSTOMER
public void testVIPCustomerWithNoDiscountCode(){
OrderCalculator calculator= new OrderCalculator();
double total = calculator.calculateTotalPrice(new double[]{100,200},"VIP",true,null);
assertEquals(240.0,total,0.01);
}


[USER=18840]@Test[/USER]
public void testRegularCustomerWithNoDiscountCode(){
OrderCalculator calculator= new OrderCalculator();
double[] items= {50.0,50.0};
String customerType= "Regular";
boolean isVip= false;
String discountCode = null;
double expect= 100.0;
double total = calculator.calculateTotalPrice(items,customerType,isVip,discountCode);
assertEquals(95,total,0.01);
}
[USER=18840]@Test[/USER]
public void testNoCustomerTpeWithNoDiscountCode(){
OrderCalculator calculator= new OrderCalculator();
double[] items= {50.0,50.0};
String customerType= "";
boolean isVip= false;
String discountCode = null;
double expect= 100;
double total = calculator.calculateTotalPrice(items,customerType,isVip,discountCode);
assertEquals(expect,total,0.01);
}

[USER=18840]@Test[/USER]
public void testPriceWithEmptyDiscountCode(){
OrderCalculator calculator= new OrderCalculator();
double[] items= {50.0,50.0};
String customerType= "";
boolean isVip= true;
String discountCode = "";

double expect= 80;
double total = calculator.calculateTotalPrice(items,customerType,isVip,discountCode);
assertEquals(expect,total,0.01);
}
[USER=18840]@Test[/USER]
public void testPriceWithWrongDiscountCode(){
OrderCalculator calculator= new OrderCalculator();
double[] items= {50.0,50.0};
String customerType= "";
boolean isVip= true;
String discountCode = "ABC";

double expect= 80;
double total = calculator.calculateTotalPrice(items,customerType,isVip,discountCode);
assertEquals(expect,total,0.01);
}
[USER=18840]@Test[/USER]
public void testVipCustomerWithSALE10(){
OrderCalculator calculator= new OrderCalculator();
double[] items= {50.0,50.0};
String customerType= "";
boolean isVip= true;
String discountCode = "SALE10";

double expect= 70;
double total = calculator.calculateTotalPrice(items,customerType,isVip,discountCode);
assertEquals(expect,total,0.01);
}
[USER=18840]@Test[/USER]
public void testVipCustomerWithWelcomes(){
OrderCalculator calculator= new OrderCalculator();
double[] items= {50.0,50.0};
String customerType= "";
boolean isVip= true;
String discountCode = "WELCOMES";

double expect= 100.0;
double total = calculator.calculateTotalPrice(items,customerType,isVip,discountCode);
assertEquals(75,total,0.01);
}
[USER=18840]@Test[/USER]
public void testRegularCustomerWithSale10(){
OrderCalculator calculator= new OrderCalculator();
double[] items= {50.0,50.0};
String customerType= "Regular";
boolean isVip= false;
String discountCode = "SALE10";

double expect= 85;
double total = calculator.calculateTotalPrice(items,customerType,isVip,discountCode);
assertEquals(expect,total,0.01);
}
[USER=18840]@Test[/USER]
public void testRegularCustomerWithWelcomes(){
OrderCalculator calculator= new OrderCalculator();
double[] items= {50.0,50.0};
String customerType= "Regular";
boolean isVip= false;
String discountCode = "WELCOMES";
double expect= 90;
double total = calculator.calculateTotalPrice(items,customerType,isVip,discountCode);
assertEquals(expect,total,0.01);
}
[USER=18840]@Test[/USER]
public void testNoTypeCustomerWithSale10(){
OrderCalculator calculator= new OrderCalculator();
double[] items= {50.0,50.0};
String customerType= "";
boolean isVip= false;
String discountCode = "SALE10";

double expect= 90;
double total = calculator.calculateTotalPrice(items,customerType,isVip,discountCode);
assertEquals(expect,total,0.01);
}
[USER=18840]@Test[/USER]
public void testNoTypeCustomerWithWelcome(){
OrderCalculator calculator= new OrderCalculator();
double[] items= {50.0,50.0};
String customerType= "";
boolean isVip= false;
String discountCode = "WELCOMES";

double expect= 95;
double total = calculator.calculateTotalPrice(items,customerType,isVip,discountCode);
assertEquals(expect,total,0.01);
}
}
:))) ta note y chang được cái ctrl c v vô thẳng bài làm =)))))) không thèm ghi ID Case luôn mà
 
bán đáp án giá 0k
 
cách setup và làm bài câu 2:

1. tạo sẵn 1 project = maven (ưu tiên dùng intellij vì nó gợi ý ngon) và cài sẵn dependency junit
2. Tạo 1 class mới copy toàn bộ code từ câu 2
3. Viết 1 class khác và copy code test mẫu đề cho (nếu không biết cách truyền input ntn thì code mẫu có chỉ cách truyền input)
4. Làm bài
copy ở đây là mình tự viết ra xong code hay sao bạn chứ làm PEA sao copy đây =))
 
Back
Bên trên Bottom