Project Question: Creating a Hollow Square with Diagonal Lines

Rumman Ansari   Software Engineer   2024-07-06 03:54:40   42 Share
Subject Syllabus DetailsSubject Details
☰ TContent
☰Fullscreen

Table of Content:

Objective:

Creating a Hollow Square with Diagonal Lines
Figure: Creating a Hollow Square with Diagonal Lines

The objective of this project is to create a Java program that generates a hollow square pattern with additional diagonal lines. The program will prompt the user to enter the number of rows, and then it will print the desired pattern based on the user's input.

Project Description:

In this project, you will implement a Java program that uses nested loops and conditional statements to print a hollow square pattern. The pattern will include diagonal lines from the top-left to bottom-right and from the top-right to bottom-left, in addition to the borders of the square.

Tasks and Requirements:

  1. Setup Development Environment:

    • Ensure you have Java Development Kit (JDK) installed.
    • Set up an Integrated Development Environment (IDE) like IntelliJ IDEA, Eclipse, or NetBeans, or use a text editor like Visual Studio Code.
  2. Understanding the Problem:

    • The program will generate a pattern based on the number of rows provided by the user.
    • The pattern will include a hollow square with diagonal lines.
  3. Implement the Program:

    • Create a Java class named HollowSquare.
    • Use a Scanner object to take user input for the number of rows.
    • Implement nested loops to generate the pattern.
    • Use conditional statements to determine when to print stars (*) and when to print spaces.
  1. Testing the Program:

    • Run the program with different inputs to ensure it produces the correct pattern.
    • Validate edge cases such as n = 1 and large values of n.
  2. Documentation:

    • Comment your code to explain the logic and flow.
    • Write a brief report explaining how the program works and include sample outputs.
  3. Submission:

    • Submit the Java source file (HollowSquare.java).
    • Include the report as a PDF or Word document.
    • Provide screenshots of the program output for different test cases.

Sample Output:

For an input of n = 12, the program should produce the following output:


Enter the number of rows: 12
************
**        **
* *      * *
*  *    *  *
*   *  *   *
*    **    *
*    **    *
*   *  *   *
*  *    *  *
* *      * *
**        **
************

Evaluation Criteria:

  • Correctness of the implemented pattern.
  • Code readability and use of comments.
  • Proper handling of user input and edge cases.
  • Quality of the documentation and sample outputs.

This project will help you understand the use of nested loops, conditional statements, and taking user input in Java. It also enhances your problem-solving skills by generating complex patterns.