Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Practical Exercises: Advanced Object Oriented Programming - Java For each of the following problems, start by developing the program logic, (Flowchart, or algorithm (pseudocode),

imageimageimage

Practical Exercises: Advanced Object Oriented Programming - Java For each of the following problems, start by developing the program logic, (Flowchart, or algorithm (pseudocode), then develop each solution in Java code. 1. Eight Queens A puzzler for chess buffs is the Eight Queens problem, which asks: Is it possible to place eight queens on an empty chessboard so that no queen is "attacking" any other (i.e., no two queens are in the same row, in the same column or along the same diagonal)? For example, if a queen is placed in the upper-left corner of the board, no other queens could be placed in any of the marked squares shown in Fig. 1. Solve the problem recursively. [Hint: Your solution should begin with the first column and look for a location in that column where a queen can be placed initially, place the queen in the first row. The solution should then recursively search the remaining columns. In the first few columns, there will be several locations where a queen may be placed. Take the first available location. If a column is reached with no possible location for a queen, the program should return to the previous column, and move the queen in that column to a new row. This continuous backing up and trying new alternatives is an example of recursive backtracking.] 2. Recursive File and Directory Manipulation Using the String-processing capabilities of textbook Chapter 14, the file and directory capabilities of Section 15.3 and a Map Section 16.10_, create an application that recursively walks a directory structure supplied by the user and reports the number of files of each file type (such as .java, .txt, .class, .docx, etc.) that exist in the specified directory path. Display the filename extensions in sorted order. Next, investigate method walk of class the Files. This method returns a stream that walks a directory and its subdirectories and returns the contents to you as a stream. Then, reimplement the first part of this exercise, using lambdas and streams, rather than recursion. 3. Calculating Factorials with Lambdas and Streams Reimplement the factorial methods of Figs. 18.3 -18.4 in the textbook page 761 to calculate factorials using lambdas and streams, rather than recursion. Submission requirements: Your submission must include a document with the logic for each problem in this assignment as well as each problem's source code. Due Session 12 * * * * * * * * * * * * * * * * * * * * * * Fig.1 Squares eliminated by placing a queen in the upper-left corner of a chessboard. 1 // Fig. 18.3: FactorialCalculator.java 2 // Recursive factorial method. 3 4 public class FactorialCalculator { 5 6 // recursive method factorial (assumes its parameter is >= 0) public static long factorial (long number) { 7 if (number 21; counter++) { 18 = System.out.printf("%d! %d%n", counter, factorial (counter)); 19 } 20 21 } 0! = 1 1! = 1 2! = 2 3! = 6 4! = 24 5! = 120 ... } 12! = 479001600 - 12! causes overflow for int variables ... 20! = 21! = 2432902008176640000 -4249290049419214848 - 21! causes overflow for long variables

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

Business Communication Developing Leaders for a Networked World

Authors: Peter Cardon

2nd edition

9814714658, 978-0073403281, 73403288, 978-9814714655

More Books

Students also viewed these Programming questions

Question

Why is money important to a business? L01

Answered: 1 week ago

Question

Define Scientific Management

Answered: 1 week ago

Question

Explain budgetary Control

Answered: 1 week ago

Question

Solve the integral:

Answered: 1 week ago

Question

What is meant by Non-programmed decision?

Answered: 1 week ago