Skip to content

Turning In #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 51 additions & 4 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,56 @@
/**
* 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) {
Scanner input = new Scanner(System.in);
String pref;
boolean isValid = false;
do {
System.out.println("Would you like me to Multiply or Add for you?");
pref = input.nextLine();
if (isAdd(pref) == true) {
isValid = true;
System.out.println("Please input an integer for me to add");
int number = input.nextInt();
System.out.println("The sum of all integers between 1 and " + number + " is: \n" + quickAdd(number));
System.out.println("Quick Maffs");
} else if (isMultiply(pref) == true) {
isValid = true;
System.out.println("Please input an integer for me to multiply");
long number = input.nextLong();
System.out.println("The product of all integers between 1 and " + number + " is: \n" + quickMultiply(number));
System.out.println("Quick Maffs");
} else {
System.out.println("Invalid input. Please try again:");
}
}
while (isValid == false) ;
}


public static boolean isMultiply(String pref){
return pref.equals("Multiply") || pref.equals("multiply");
}

public static boolean isAdd(String pref){
return pref.equals("Add") || pref.equals("add");
}

public static int quickAdd (int number){
int answer = 0;
for (int i = 1; i <= number; i++){
answer = answer +i;
}
return answer;
}

public static long quickMultiply (long number){
long answer = 1;
for (int i = 1; i <= number; i++){
answer = answer * i;
}
return answer;
}

}