From 7ff9c3c77e7a7f1cd039d5856134d03e54f812a4 Mon Sep 17 00:00:00 2001 From: Suzette Person <suzette.person@unl.edu> Date: Tue, 2 Oct 2018 21:41:23 -0500 Subject: [PATCH] updates based on teaching plan --- .../before_and_after/BookAfterRefactor.java | 42 ++++++++++++++++ .../soft160/before_and_after/BookBefore.java | 27 +++++++--- .../before_and_after/BookGUIBefore.java | 21 ++++++++ .../InClassAfterRefactor.java | 13 +++++ .../before_and_after/InClassBefore.java | 26 +++++++--- .../BookAfterRefactorTest.java | 34 +++++++++++++ .../before_and_after/BookBeforeTest.java | 50 +++++++++---------- .../InClassAfterRefactorTest.java | 34 +++++++++++++ .../before_and_after/InClassBeforeTest.java | 50 +++++++++---------- 9 files changed, 227 insertions(+), 70 deletions(-) create mode 100644 src/main/java/edu/unl/cse/soft160/before_and_after/BookAfterRefactor.java create mode 100644 src/main/java/edu/unl/cse/soft160/before_and_after/BookGUIBefore.java create mode 100644 src/main/java/edu/unl/cse/soft160/before_and_after/InClassAfterRefactor.java create mode 100644 src/test/java/edu/unl/cse/soft160/before_and_after/BookAfterRefactorTest.java create mode 100644 src/test/java/edu/unl/cse/soft160/before_and_after/InClassAfterRefactorTest.java 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 0000000..af9650e --- /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 f697a45..40d2d1a 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 0000000..754648c --- /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 0000000..bfbd61a --- /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 12c2916..ac1dcd2 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 0000000..685b016 --- /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 01270b4..a904d1e 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 0000000..630b517 --- /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 612b415..f6afca4 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); + } } -- GitLab