Question
I need the class diagram and the sequence diagram for the following code: 1. import java.util.Scanner; public class Factorials { public static void main(String[] args)
I need the class diagram and the sequence diagram for the following code:
1.
import java.util.Scanner;
public class Factorials { public static void main(String[] args) {
String keepGoing = "y"; Scanner scan = new Scanner(System.in); while (keepGoing.equals("y") || keepGoing.equals("Y")) { System.out.print("Enter an integer: "); int val = scan.nextInt();
try { System.out.println("Factorial(" + val + ") = " + MathUtils.factorial(val)); }catch(IllegalArgumentException ex) { ex.printStackTrace(); }
System.out.print("Another factorial? (y/n) "); keepGoing = scan.next();
} }
}
2.
public class MathUtils {
public static int factorial(int n) throws IllegalArgumentException { if (n < 0) throw new IllegalArgumentException ("Factorial: n("+n+") must be a non-negative"); //Passed message to Constructor if(n>16) throw new IllegalArgumentException ("Factorial: n("+n+") can not be greater than 16"); int fac = 1; for (int i=n; i>0; i--) fac *= i; return fac; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started