Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL 10 High Performance Expert Techniques For Query Optimization High Availability And Efficient Database Maintenance

Authors: Ibrar Ahmed ,Gregory Smith ,Enrico Pirozzi

3rd Edition

1788474481, 978-1788474481

More Books

Students also viewed these Databases questions

Question

=+5. What change do you need to make to achieve desired position?

Answered: 1 week ago

Question

Explain the guideline for job description.

Answered: 1 week ago

Question

What is job description ? State the uses of job description.

Answered: 1 week ago

Question

What are the objectives of job evaluation ?

Answered: 1 week ago

Question

Write a note on job design.

Answered: 1 week ago

Question

Employ effective vocal cues Employ effective visual cues

Answered: 1 week ago