Skip to content
Snippets Groups Projects
Commit 7ff9c3c7 authored by Suzette J Person's avatar Suzette J Person
Browse files

updates based on teaching plan

parent 21ce9f70
No related branches found
No related tags found
No related merge requests found
Showing
with 227 additions and 70 deletions
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);
}
}
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 + ".");
}
}
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 + ".");
}
}
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
}
}
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 + ".");
}
}
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);
}
}
......@@ -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
{
public class BookBeforeTest extends TestCase {
/**
* Create the test case
*
* @param testName name of the test case
* @param testName
* name of the test case
*/
public BookBeforeTest( String testName )
{
public BookBeforeTest(String testName) {
super(testName);
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
public static Test suite() {
return new TestSuite(BookBeforeTest.class);
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
public void testBookBefore() {
assertTrue(true);
}
}
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);
}
}
......@@ -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
{
public class InClassBeforeTest extends TestCase {
/**
* Create the test case
*
* @param testName name of the test case
* @param testName
* name of the test case
*/
public InClassBeforeTest( String testName )
{
public InClassBeforeTest(String testName) {
super(testName);
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
public static Test suite() {
return new TestSuite(InClassBeforeTest.class);
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
public void testInClassBefore() {
assertTrue(true);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment