Skip to content
Snippets Groups Projects
Commit ea74d057 authored by Christopher Bohn's avatar Christopher Bohn :thinking:
Browse files

Added result of refactoring the in-class example

parent 7ecf8939
No related branches found
No related tags found
No related merge requests found
package edu.unl.cse.soft160.before_and_after; package edu.unl.cse.soft160.before_and_after;
import java.util.Scanner;
/** /**
* Command-Line Example from class after refactoring * Command-Line Example from class after refactoring
* <p> * <p>
...@@ -7,7 +9,29 @@ package edu.unl.cse.soft160.before_and_after; ...@@ -7,7 +9,29 @@ package edu.unl.cse.soft160.before_and_after;
* shipping cost. * shipping cost.
*/ */
public class InClassAfterRefactor { public class InClassAfterRefactor {
private static double getShippingWeight(String prompt, Scanner scanner) {
System.out.print(prompt);
double weightOfItem = Double.parseDouble(scanner.nextLine());
return weightOfItem;
}
private static void displayResult(double shippingCost, double weightOfFirstItem, double weightOfSecondItem) {
System.out.println("Weight of the items is " + weightOfFirstItem + " and " + weightOfSecondItem
+ " and the shipping cost is " + shippingCost + ".");
}
private static double computeShippingCost(double weightFirstItem, double weightSecondItem) {
double shippingCost = (weightFirstItem + weightSecondItem) * 2.50;
return shippingCost;
}
public static void main(String[] args) { public static void main(String[] args) {
// Implementation goes here Scanner scanner = new Scanner(System.in);
double weightFirstItem = getShippingWeight("Enter the weight of the first item: ", scanner);
double weightSecondItem = getShippingWeight("Enter the weight of the second item: ", scanner);
scanner.close();
double shippingCost = computeShippingCost(weightFirstItem, weightSecondItem);
displayResult(shippingCost, weightFirstItem, weightSecondItem);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment