Project Assignment: Creating an X Pattern
Table of Content:
Project Title:
Generating an X Pattern
Objective:
The objective of this project is to create a Java program that generates an X pattern based on user input. The program will prompt the user to enter the size of the X, and then it will print the desired pattern.
Project Description:
In this project, you will implement a Java program that uses nested loops and conditional statements to print an X pattern. The pattern will be determined by the size provided by the user, and it will consist of stars (*
) forming the shape of an X.
Tasks and Requirements:
-
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.
-
Understanding the Problem:
- The program will generate an X pattern based on the size provided by the user.
- The pattern will include stars (
*
) forming two diagonal lines that intersect in the center.
-
Implement the Program:
- Create a Java class named
XPattern
. - Use a
Scanner
object to take user input for the size of the X. - Implement nested loops to generate the pattern.
- Use conditional statements to determine when to print stars (
*
) and when to print spaces.
- Create a Java class named
-
Code Implementation:
- Implement the corrected and properly formatted code in the
XPattern
class.
- Implement the corrected and properly formatted code in the
-
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 ofn
.
-
Documentation:
- Comment your code to explain the logic and flow.
- Write a brief report explaining how the program works and include sample outputs.
-
Submission:
- Submit the Java source file (
XPattern.java
). - Include the report as a PDF or Word document.
- Provide screenshots of the program output for different test cases.
- Submit the Java source file (
Sample Output:
For an input of n = 3
, the program should produce the following output:
* * * * * * * * *
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.