Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I AM GETTING AN UNREACHABLE STATEMENT ERROR FOR THIS CODE CAN YOU PLEASE HELP FIX THE CODE? * Create a new bag that contains all

I AM GETTING AN UNREACHABLE STATEMENT ERROR FOR THIS CODE CAN YOU PLEASE HELP FIX THE CODE?

* Create a new bag that contains all the elements from two other bags -- note that * this is a class method NOT an instance method and must be called with class * name qualifier. * @param b1 * the first of two bags * @param b2 * the second of two bags * @pre. * Neither b1 nor b2 is null, and b1.size() + b2.size() cannot * exceed MAX_CAPACITY * @post. * bag referenced by b1 and bag referenced by b2 are not altered * @return * the union of b1 and b2 * @exception NullPointerException * Indicates that one of the arguments is null. * @exception OutOfMemoryError * Indicates insufficient memory for the new bag. Only happens * when not enough dynamic memory to allocate a new bag of * adequate size. **/ public static DoubleArrayBag union(DoubleArrayBag b1, DoubleArrayBag b2) { if ( b1 == null || b2 == null ) { throw new NullPointerException("one or both bags reference is null"); }

// guarantee that the new bag has exactly the capacity needed to // hold all items from both b1 and b2 and then copy the items from // b1 and then b2 into the new bag

//DoubleArrayBag newBag = null; // = new DoubleArrayBag( ?? ); //STUDENT WORK HERE DoubleArrayBag newBag = new DoubleArrayBag(b1); newBag.plusEquals(b2); return newBag;

/* correct below return */ return b1; }

###CAN YOU HELP ME CODE THIS PROGRAM SO IT LOOKS LIKE THIS PICTURE ALSO WITH THE SPECIFICATIONS LISTED BELOW

image text in transcribed

Create a program that checks whether a number is a prime number and displays the total number of factors if it is not a prime number Console Prime Number Checker Please enter an integer between 1 and 5000: 1 Invalid integer. Please try again. Please enter an integer between 1 and 5000: 2 2 is a prime number Try again? (y): y Please enter an integer between 1 and 5000: 3 3 is a prime number Try again? (y): y Please enter an integer between 1 and 5000: 4 4 is NOT a prime number It has 3 factors Try again? (y): y Please enter an integer between 1 and 5000: 6 6 is NOT a prime number It has 4 factors Try again? (y): n Bye! Specifications A prime number is only divisible by two factors (1 and itself). For example, 7 is a prime number because it is only divisible by 1 and 7 If the number is not a prime number, the program should display its number of factors. For example, 6 has four factors (1, 2, 3, and 6) Store the code that gets a valid integer for this program in its own function Store the code that calculates the number of factors for a number in its own function. Store the rest of the code that gets input and displays output in the main function

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

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

More Books

Students also viewed these Databases questions