diff --git a/src/main/java/edu/unl/cse/soft160/before_and_after/BookAfterRefactor.java b/src/main/java/edu/unl/cse/soft160/before_and_after/BookAfterRefactor.java new file mode 100644 index 0000000000000000000000000000000000000000..af9650e28ecf13bd2812f0316527e9e51a0b3238 --- /dev/null +++ b/src/main/java/edu/unl/cse/soft160/before_and_after/BookAfterRefactor.java @@ -0,0 +1,42 @@ +package edu.unl.cse.soft160.before_and_after; + +import java.util.Scanner; + +/** + * Command-Line Example from SEN Chapter 6 after refactoring + */ + +public class BookAfterRefactor { + + // Input and Conversion + private static double requestNumber(Scanner scanner) { + System.out.print("Enter the number: "); + String augendText = scanner.nextLine(); + double augend = Double.parseDouble(augendText); + return augend; + } + + // Conversion and Output + private static void reportSum(double sum) { + System.out.println("The sum is " + sum + "."); + } + + // Computation + private static double compute(double augend, double addend) { + double sum = augend + addend; + return sum; + } + + public static void main(String[] args) { + // Input and Conversion + Scanner scanner = new Scanner(System.in); + double augend = requestNumber(scanner); + double addend = requestNumber(scanner); + scanner.close(); + // Computation + double sum = compute(augend, addend); + // Conversion and Output + reportSum(sum); + } + +} diff --git a/src/main/java/edu/unl/cse/soft160/before_and_after/BookBefore.java b/src/main/java/edu/unl/cse/soft160/before_and_after/BookBefore.java index f697a45da09b577e041a865fe6042a1ca259b0cf..40d2d1aacdd24685f57fe76e6d2f25e1e4f8628d 100644 --- a/src/main/java/edu/unl/cse/soft160/before_and_after/BookBefore.java +++ b/src/main/java/edu/unl/cse/soft160/before_and_after/BookBefore.java @@ -1,13 +1,24 @@ package edu.unl.cse.soft160.before_and_after; +import java.util.Scanner; + /** - * Hello world! - * + * Command-Line Example from SEN Chapter 6 written as a single method */ -public class BookBefore -{ - public static void main( String[] args ) - { - System.out.println( "Hello World!" ); - } +public class BookBefore { + public static void main(String[] args) { + // Input and Conversion + Scanner scanner = new Scanner(System.in); + System.out.print("Enter the augend: "); + String augendText = scanner.nextLine(); + double augend = Double.parseDouble(augendText); + System.out.print("Enter the addend: "); + String addendText = scanner.nextLine(); + double addend = Double.parseDouble(addendText); + scanner.close(); + // Computation + double sum = augend + addend; + // Conversion and Output + System.out.println("The sum is " + sum + "."); + } } diff --git a/src/main/java/edu/unl/cse/soft160/before_and_after/BookGUIBefore.java b/src/main/java/edu/unl/cse/soft160/before_and_after/BookGUIBefore.java new file mode 100644 index 0000000000000000000000000000000000000000..754648c7f7d03463e9afe05bdf186b3bebcaeda4 --- /dev/null +++ b/src/main/java/edu/unl/cse/soft160/before_and_after/BookGUIBefore.java @@ -0,0 +1,21 @@ +package edu.unl.cse.soft160.before_and_after; + +import static javax.swing.JOptionPane.showInputDialog; +import static javax.swing.JOptionPane.showMessageDialog; + +/** + * GUI Example from SEN Chapter 6 written as a single method + */ +public class BookGUIBefore { + public static void main(String[] args) { + // Input and Conversion + String augendText = showInputDialog(null, "Enter the augend: "); + double augend = Double.parseDouble(augendText); + String addendText = showInputDialog(null, "Enter the addend: "); + double addend = Double.parseDouble(addendText); + // Computation + double sum = augend + addend; + // Conversion and Output + showMessageDialog(null, "The sum is " + sum + "."); + } +} diff --git a/src/main/java/edu/unl/cse/soft160/before_and_after/InClassAfterRefactor.java b/src/main/java/edu/unl/cse/soft160/before_and_after/InClassAfterRefactor.java new file mode 100644 index 0000000000000000000000000000000000000000..bfbd61ab2921bc753645574f1f70df7aa2141dff --- /dev/null +++ b/src/main/java/edu/unl/cse/soft160/before_and_after/InClassAfterRefactor.java @@ -0,0 +1,13 @@ +package edu.unl.cse.soft160.before_and_after; + +/** + * Command-Line Example from class after refactoring + * + * Problem statement: Given the weight of two items, display the weights and the + * shipping cost. + */ +public class InClassAfterRefactor { + public static void main(String[] args) { + // Implementation goes here + } +} diff --git a/src/main/java/edu/unl/cse/soft160/before_and_after/InClassBefore.java b/src/main/java/edu/unl/cse/soft160/before_and_after/InClassBefore.java index 12c29169845a316ce914577aa018d7e3158c7b9a..ac1dcd20ffdccb75dbd2f820dc67906e6d0c9913 100644 --- a/src/main/java/edu/unl/cse/soft160/before_and_after/InClassBefore.java +++ b/src/main/java/edu/unl/cse/soft160/before_and_after/InClassBefore.java @@ -1,13 +1,23 @@ package edu.unl.cse.soft160.before_and_after; +import java.util.Scanner; + /** - * Hello world! - * + * Command-Line Example from class written as a single method */ -public class InClassBefore -{ - public static void main( String[] args ) - { - System.out.println( "Hello World!" ); - } +public class InClassBefore { + public static void main(String[] args) { + // Input and Conversion + Scanner scanner = new Scanner(System.in); + System.out.print("Enter the weight of the first item: "); + double weightFirstItem = Double.parseDouble(scanner.nextLine()); + System.out.print("Enter the weight of the second item: "); + double weightSecondItem = Double.parseDouble(scanner.nextLine()); + scanner.close(); + // Computation + double shippingCost = (weightFirstItem + weightSecondItem) * 2.50; + // Conversion and Output + System.out.println("Weight of the items is " + weightFirstItem + " and " + weightSecondItem + + " and the shipping cost is " + shippingCost + "."); + } } diff --git a/src/test/java/edu/unl/cse/soft160/before_and_after/BookAfterRefactorTest.java b/src/test/java/edu/unl/cse/soft160/before_and_after/BookAfterRefactorTest.java new file mode 100644 index 0000000000000000000000000000000000000000..685b0162f35bf27edeee4d84d81128f12c86a48c --- /dev/null +++ b/src/test/java/edu/unl/cse/soft160/before_and_after/BookAfterRefactorTest.java @@ -0,0 +1,34 @@ +package edu.unl.cse.soft160.before_and_after; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for BookAfterRefactor app + */ +public class BookAfterRefactorTest extends TestCase { + /** + * Create the test case + * + * @param testName + * name of the test case + */ + public BookAfterRefactorTest(String testName) { + super(testName); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() { + return new TestSuite(BookAfterRefactorTest.class); + } + + /** + * Rigourous Test :-) + */ + public void testBookAfterRefactor() { + assertTrue(true); + } +} diff --git a/src/test/java/edu/unl/cse/soft160/before_and_after/BookBeforeTest.java b/src/test/java/edu/unl/cse/soft160/before_and_after/BookBeforeTest.java index 01270b4011226c40229ad066d729ee5214406f7d..a904d1e25ff8762d9b4350d0d5d986ce2a53bf6f 100644 --- a/src/test/java/edu/unl/cse/soft160/before_and_after/BookBeforeTest.java +++ b/src/test/java/edu/unl/cse/soft160/before_and_after/BookBeforeTest.java @@ -5,34 +5,30 @@ import junit.framework.TestCase; import junit.framework.TestSuite; /** - * Unit test for simple App. + * Unit test for BookBefore app */ -public class BookBeforeTest - extends TestCase -{ - /** - * Create the test case - * - * @param testName name of the test case - */ - public BookBeforeTest( String testName ) - { - super( testName ); - } +public class BookBeforeTest extends TestCase { + /** + * Create the test case + * + * @param testName + * name of the test case + */ + public BookBeforeTest(String testName) { + super(testName); + } - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( BookBeforeTest.class ); - } + /** + * @return the suite of tests being tested + */ + public static Test suite() { + return new TestSuite(BookBeforeTest.class); + } - /** - * Rigourous Test :-) - */ - public void testApp() - { - assertTrue( true ); - } + /** + * Rigourous Test :-) + */ + public void testBookBefore() { + assertTrue(true); + } } diff --git a/src/test/java/edu/unl/cse/soft160/before_and_after/InClassAfterRefactorTest.java b/src/test/java/edu/unl/cse/soft160/before_and_after/InClassAfterRefactorTest.java new file mode 100644 index 0000000000000000000000000000000000000000..630b5176c218afbbe2aa0d95e38ab07f8ef39af6 --- /dev/null +++ b/src/test/java/edu/unl/cse/soft160/before_and_after/InClassAfterRefactorTest.java @@ -0,0 +1,34 @@ +package edu.unl.cse.soft160.before_and_after; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for InClassAfter app + */ +public class InClassAfterRefactorTest extends TestCase { + /** + * Create the test case + * + * @param testName + * name of the test case + */ + public InClassAfterRefactorTest(String testName) { + super(testName); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() { + return new TestSuite(InClassAfterRefactorTest.class); + } + + /** + * Rigourous Test :-) + */ + public void testInClassAfterRefactor() { + assertTrue(true); + } +} diff --git a/src/test/java/edu/unl/cse/soft160/before_and_after/InClassBeforeTest.java b/src/test/java/edu/unl/cse/soft160/before_and_after/InClassBeforeTest.java index 612b415856ec640e2205722d63a6568e57bcac12..f6afca47b039b84ab006506918a726d7a91d50ef 100644 --- a/src/test/java/edu/unl/cse/soft160/before_and_after/InClassBeforeTest.java +++ b/src/test/java/edu/unl/cse/soft160/before_and_after/InClassBeforeTest.java @@ -5,34 +5,30 @@ import junit.framework.TestCase; import junit.framework.TestSuite; /** - * Unit test for simple App. + * Unit test for InClassBefore */ -public class InClassBeforeTest - extends TestCase -{ - /** - * Create the test case - * - * @param testName name of the test case - */ - public InClassBeforeTest( String testName ) - { - super( testName ); - } +public class InClassBeforeTest extends TestCase { + /** + * Create the test case + * + * @param testName + * name of the test case + */ + public InClassBeforeTest(String testName) { + super(testName); + } - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( InClassBeforeTest.class ); - } + /** + * @return the suite of tests being tested + */ + public static Test suite() { + return new TestSuite(InClassBeforeTest.class); + } - /** - * Rigourous Test :-) - */ - public void testApp() - { - assertTrue( true ); - } + /** + * Rigourous Test :-) + */ + public void testInClassBefore() { + assertTrue(true); + } }