|
|
8 anos atrás | |
|---|---|---|
| src/test/java/org/zipcoder/store | 8 anos atrás | |
| .gitignore | 8 anos atrás | |
| README.md | 8 anos atrás | |
| pom.xml | 8 anos atrás |
In the test folder, there is a ProductTest with most of the tested commented out.
Product is red. That's because we need to create a new Class named Product. The file should be in src/main/java/org.zipcoder.store.
For the get and set test, you need to create a field and methods to get and set the field. Ex:
public class Book {
private String title;
public void setTitle(String title){
this.title = title;
}
public String getTitle() {
return this.title;
}
}
Continue to uncomment the test and add code to make the test pass
For the product description, it should be in this format title (Color: color, Size: size)
Hat (Color: Yellow, Size: LG)A cart has an array of Product.
CartTest and uncomment line 9-13. To make the test pass:
CarttestGetProducts test passtestGetSetDiscount test pass:
discountgetProductTotal tests to pass, you need add all the product prices together and return the result.The goal of this exercise is to know how to create and test a class.
CreditCardcardHolderName of the type String
CreditCard classString numberint expiredMonthint expiredYeargetDescription
getDescription should return [cardHolderName] [last 4 digit of the number] [expiredMonth]/[expiredYear]
Tia Mowry 4551 10/2019CreditCard field to the Cart class
creditCard fieldThe goal of this exercise is to change the products array in the Cart class to an ArrayList.
CartTest, change the products array to an ArrayList
java
ArrayList<Product> products = new ArrayList();
products.add(new Product("Shirt", 15.01));
Add this test to the CartTest class
@Test
public void testAddToCard(){
// Given
ArrayList<Product> products = new ArrayList();
Cart cart = new Cart(products);
// When
Product shirt = new Product("Shirt", 1.99);
cart.addProduct(shirt);
// Then
double expectedTotal = 1.99;
double actualTotal = cart.getProductTotal();
Assert.assertEquals(expectedTotal, actualTotal, DELTA);
}
addProduct method to the Cart class