From fa44653af84200648b4a6c7281e3dfd15dd42c81 Mon Sep 17 00:00:00 2001 From: Ahson Chaudhary Date: Thu, 8 Feb 2018 16:08:15 -0500 Subject: [PATCH 1/2] I completed this project finally --- src/main/java/Main.java | 48 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 1dbc0cb..ce58086 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,9 +1,53 @@ /** * Created by iyasuwatts on 10/17/17. */ + +import java.util.Scanner; + public class Main { - public static void main(String[] args){ + public static void main(String[] args) { + + // TO DO: + // Ask for an input value of integer n + // Create a scanner to store to integer n and string choice of sum or product + // Incorporate a switch statement for string choice + // Input from the switch statement decides the method that will execute + // + +//------------------------------------------------------------------------------------------------------------------- + + // THIS IS 1 SCANNER WITH 2 INPUTS + Scanner sn = new Scanner(System.in); + + System.out.println("Enter an integer: "); + String nAsAString = sn.nextLine(); + int n = Integer.parseInt(nAsAString); + + System.out.println("Enter an option of \"sum\" or \"product: \""); + String choice = sn.nextLine(); + + int theSum = 0; + int theProduct = 1; + + + if (choice.equalsIgnoreCase("sum")) { + for (int i = 0; i <= n; i++) { + theSum += i; + } + + System.out.println(theSum); + } else if (choice.equalsIgnoreCase("product")) { + for (int i = 1; i <= n; i++) { + theProduct *= i; + } + + System.out.println(theProduct); + + } else { + + System.out.println("You did not submit a valid choice"); + } } -} +} \ No newline at end of file From 98076637236707297d46b921ea72c51b93cd5f7c Mon Sep 17 00:00:00 2001 From: Ahson Chaudhary Date: Thu, 8 Feb 2018 17:09:16 -0500 Subject: [PATCH 2/2] done --- src/main/java/Main.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index ce58086..d7f5df6 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -24,6 +24,8 @@ public static void main(String[] args) { String nAsAString = sn.nextLine(); int n = Integer.parseInt(nAsAString); + + System.out.println("Enter an option of \"sum\" or \"product: \""); String choice = sn.nextLine();