diff --git a/StudentClass/MyStudentTest.java b/StudentClass/MyStudentTest.java new file mode 100644 index 0000000..42b0db0 --- /dev/null +++ b/StudentClass/MyStudentTest.java @@ -0,0 +1,57 @@ +import org.junit.*; +/**************************************************** + * MyStudentTest - to test the class Student + * + * @author Resendiz + * @version January 2021 + ****************************************************/ + +public class MyStudentTest { + + /****************************************************** + * Test default constructor - no input parameters + *****************************************************/ + @Test + public void testDefaultConstructor() { + Student s = new Student(); + Assert.assertEquals("Student name should be set to Louie", "Louie", + s.getName()); + Assert.assertEquals("GPA should be set to 1.0", + 1.0, s.getGPA(),0.1); + } + + /****************************************************** + * Test setName + *****************************************************/ + @Test + public void testSetName() { + Student s = new Student(); + s.setName("Jon"); + Assert.assertEquals("Student name should be set to Jon", "Jon", + s.getName()); + } + + /****************************************************** + * Test setGPA + *****************************************************/ + @Test + public void testSetGPA() { + Student s = new Student(); + s.setGPA(4.0); + Assert.assertEquals("GPA should be 4.0 after being to max", + 4.0, s.getGPA(),0.1); + } + + /****************************************************** + * Test Types + *****************************************************/ + @Test + public void testTypes() { + Student s = new Student(); + + //Assert.assertEquals("The type of name should be string", ); + Assert.assertEquals("The type of name should be string", + String.class, s.getName().getClass()); + } + +} \ No newline at end of file diff --git a/calculator/Calculator.java b/calculator/Calculator.java new file mode 100644 index 0000000..77b8785 --- /dev/null +++ b/calculator/Calculator.java @@ -0,0 +1,57 @@ +/* + * Build class called Calculator that emulates basic functions of a calc + * add sub mult div and clear + * one private member field, double value, for the calcs current val + * + * public Calculator() - set field to 0.0 + * public void add(double val) - add to field + * public void subtract(double val) - remove from field + * public void multiply(double val) - multiply field + * public void divide(double val) - divide field + * public void clear() - set to 0.0 + * public double getValue() - return field + * + * Given two double input values num1 and num 2, outputs following values: + * + * 1. Inital value of field value + * 2. value after adding num1 + * 3. value after mult by 3 + * 4. value after sub num2 + * 5. value after dividing by 2 + * 6. value after calling clear + * + * sample: + * input: 10.0 5.0 + * output: + * 0.0 + * 10.0 + * 30.0 + * 25.0 + * 12.5 + * 0.0 + */ + +/* Comments + * It's interesting. A long long time ago, when I was still barely able + * to make QBASIC beep and take inkey$ I thought a calculator woul be + * the perfect project to begin programming, and it gave me grief + * though now, it's easy. + * To be fair though, I don't think I even had a grasp of functions at the time + */ + + +public class Calculator{ + private double value; + + public Calculator(){ + this.value = 0; + } + + public void add(double val){ this.value += val; } + public void subtract(double val){ this.value -=val; } + public void multiply(double val){ this.value *=val; } + public void divide(double val){ this.value /=val; } + public void clear(){ this.value = 0; } + public double getValue(){ return this.value; } + +} diff --git a/calculator/MyCalculatorTest.java b/calculator/MyCalculatorTest.java new file mode 100644 index 0000000..2971816 --- /dev/null +++ b/calculator/MyCalculatorTest.java @@ -0,0 +1,69 @@ +import org.junit.*; +/**************************************************** + * MyCalculatorTest - to test the class Calculator + * + * @author Resendiz + * @version January 2021 + ****************************************************/ + +public class MyCalculatorTest { + + /****************************************************** + * Test default constructor - no input parameters + *****************************************************/ + @Test + public void testDefaultConstructor() { + Calculator calc = new Calculator(); + Assert.assertEquals("Calculator Value should be 0.0 at construction", + 0.0, calc.getValue(),0.1); + } + + /****************************************************** + * Test add + *****************************************************/ + @Test + public void testAdd() { + Calculator calc = new Calculator(); + calc.add(10); + calc.add(20); + Assert.assertEquals("If you add 10 plus 20 you need 30 as result", + 30.0, calc.getValue(),0.1); + } + + /****************************************************** + * Test multiplication + *****************************************************/ + @Test + public void testMultiplication() { + Calculator calc = new Calculator(); + calc.add(10); + calc.multiply(4); + Assert.assertEquals("If you multiply 10 times 4 you get 40 as result", + 40.0, calc.getValue(),0.1); + } + + /****************************************************** + * Test division + *****************************************************/ + @Test + public void testDivision() { + Calculator calc = new Calculator(); + calc.add(40); + calc.divide(4); + Assert.assertEquals("If you divide 40 by 4 you get 10 as result", + 10.0, calc.getValue(),0.1); + } + + /****************************************************** + * Test clear + *****************************************************/ + @Test + public void testClear() { + Calculator calc = new Calculator(); + calc.add(40); + calc.divide(4); + calc.clear(); + Assert.assertEquals("You should have 0.0 when you clear", + 0.0, calc.getValue(),0.1); + } +} diff --git a/calculator/testCalculator.java b/calculator/testCalculator.java new file mode 100644 index 0000000..ad02bc1 --- /dev/null +++ b/calculator/testCalculator.java @@ -0,0 +1,19 @@ +public class testCalculator{ + public static void main(String[] args){ + Calculator calc = new Calculator(); + double num1 = 10.0; + double num2 = 5.0; + + System.out.println(calc.getValue()); + calc.add(num1); + System.out.println(calc.getValue()); + calc.multiply(3); + System.out.println(calc.getValue()); + calc.subtract(num2); + System.out.println(calc.getValue()); + calc.divide(2); + System.out.println(calc.getValue()); + calc.clear(); + System.out.println(calc.getValue()); + } +} diff --git a/exact-change/moneyChange.java b/old/exact-change/moneyChange.java similarity index 100% rename from exact-change/moneyChange.java rename to old/exact-change/moneyChange.java diff --git a/productClass/MyProductTest.java b/productClass/MyProductTest.java new file mode 100644 index 0000000..9a9084f --- /dev/null +++ b/productClass/MyProductTest.java @@ -0,0 +1,79 @@ +import org.junit.*; +/**************************************************** + * MyStudentTest - to test the class Product + * + * @author Resendiz + * @version January 2021 + ****************************************************/ + +public class MyProductTest { + + /****************************************************** + * Test overloaded constructor - with input parameters + *****************************************************/ + @Test + public void testOverloadedConstructor() { + Product p = new Product("SKU987", 4.50, 50); + Assert.assertEquals("Product code should be ","SKU987", + p.getCode()); + Assert.assertEquals("Price should be set to $4.50", + 4.50, p.getPrice(), 0.1); + Assert.assertEquals("Count should be set to 50", + 50, p.getCount()); + } + + /****************************************************** + * Test setCode + *****************************************************/ + @Test + public void testSetCode() { + Product p = new Product("SKU987", 4.50, 50); + p.setCode("SKU123"); + Assert.assertEquals("Product code should be ","SKU123", + p.getCode()); + } + + /****************************************************** + * Test setPrice + *****************************************************/ + @Test + public void testSetPrice() { + Product p = new Product("SKU987", 4.50, 50); + p.setPrice(9.50); + Assert.assertEquals("Price should be set to $9.50", + 9.50, p.getPrice(), 0.1); + } + + /****************************************************** + * Test setCount + *****************************************************/ + @Test + public void testSetCount() { + Product p = new Product("SKU987", 4.50, 50); + p.setCount(25); + Assert.assertEquals("Count should be set to 25", + 25, p.getCount()); + } + + /****************************************************** + * Test addInventory + *****************************************************/ + @Test + public void testAddInventory() { + Product p = new Product("SKU987", 4.50, 50); + p.addInventory(25); + Assert.assertEquals("Count should be set to 75", + 75, p.getCount()); + } + + /****************************************************** + * Test sellInventory + *****************************************************/ + @Test + public void testSellInventory() { + Product p = new Product("SKU987", 4.50, 50); + p.sellInventory(25); + Assert.assertEquals("Count should be set to 25", + 25, p.getCount()); + } +}