JPR Report
JPR Report
JPR Report
On
“Interactive Java Pattern Generator”
Submitted on “20-03-2024”
By
1. Shaikh Umar
Under Guidance of
“Ms. Iffat Salim”
In
Certificate
This is to certify that Mr. /Ms./Mrs.
Enrollment No: of Semester of Diploma in Computer
Engineering at Anjuman I Islam’s Abdul Razzak Kalsekar Polytechnic, has
completed the Micro Project satisfactorily in Subject in
the academic year 2023-2024 as per the MSBTE prescribed curriculum of I
Scheme.
Head of
Institute
Annexure – I
Micro-Project Proposal
Annexure – II
Micro-Project Proposal
Skill Developed:
1. Java programming proficiency
2. Object-oriented programming (OOP) concepts
3. Problem-solving and algorithmic thinking
4. User input handling
5. Exception handling
6. Modular programming
7. Code reusability and extensibility
8. Logical reasoning
9. Hands-on experience with software development practices
10. Understanding of shape pattern generation techniques.
Application:
1. Console-based shape pattern generator
2. Educational tool for teaching Java programming concepts
3. Practical exercise for reinforcing OOP principles
4. Code example for demonstrating modular design
5. Resource for learning user input and exception handling in Java
6. Platform for experimenting with different shape pattern algorithms
7. Tool for enhancing problem-solving skills through pattern construction
8. Interactive Java project for self-paced learning or classroom instruction
9. Demonstration of real-world application of programming concepts
10. Prototype for potential integration into larger software projects or educational
curricula.
Names of Team Members with Enrollment No.:
1. ………………………………………………………………
ANNEXURE II
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
Sr. No Topic
1 Introduction
2 Hardware and Software Used
3 Algorithm
4 Flowchart
5 Code
6 Output
7 Conclusion
8 Reference
.
INTRODUCTION
The "Interactive Java Pattern Generator" is a versatile software tool designed to facilitate the
creation of various geometric patterns. With an intuitive user interface and robust system
architecture, the application allows users to select from a range of pattern types and customize
parameters such as size and shape. By leveraging Java programming, the project aims to provide
a seamless experience for pattern generation and user interaction, catering to educational,
creative, and practical needs in diverse contexts.
Step 1: Start
Step 2: Define the main method and declare the necessary variables, including a Scanner object
to read user input.
Step 3: Print a menu of options for the user to choose from, including "1. Hollow Rectangle",
"2. Solid Rectangle", "3. Half Pyramid", "4. Diamond", and "5. Triangle".
Step 5: Use a switch statement to determine which type of rectangle the user has chosen.
Step 6: For each case, create an instance of the appropriate class (HollowRectangle,
SolidRectangle, HalfPyramid, Diamond, or Triangle) and call its Logic() method to print the
pattern.
Step 7: If the user's choice is not valid (i.e., not between 1 and 5), throw an InvalidChoice
exception and catch it to display an error message.
Step 8: Finally, print a message to the user indicating that the program has ended.
Step 9: Stop
FLOWCHART
Start
FLOWCHART:
Print menu
Switch Statement
Default:Invalid Choice
END
CODE
import java.util.*;
interface LogicForEachOne {
public void Logic();
}
class PatternInputFromUser implements LogicForEachOne {
protected int rows;
protected int columns;
protected Scanner sc;
public void Logic() {
}
}
class HollowRectangle extends PatternInputFromUser {
public void Logic() {
sc = new Scanner(System.in);
System.out.println("Enter the number of rows");
rows = sc.nextInt();
System.out.println("Enter the number of columns");
columns = sc.nextInt();
System.out.println("Here is the Pattern in the Hollow rectangular format");
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= columns; j++) {
if (i == 1 || i == rows || j == 1 || j == columns) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}
}
class SolidRectangle extends PatternInputFromUser {
public void Logic() {
sc = new Scanner(System.in);
System.out.println("Enter the number of rows");
rows = sc.nextInt();
System.out.println("Enter the number of columns");
columns = sc.nextInt();
System.out.println("Here is the Pattern in the Solid rectangular format");
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= columns; j++) {
System.out.print("*");
}
System.out.println();
}
}}
class HalfPyramid extends PatternInputFromUser {
public void Logic() {
sc = new Scanner(System.in);
System.out.println("Enter the number of rows");
rows = sc.nextInt();
System.out.println("Here is the Pattern in the Half Pyramid rectangular format");
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= i; j++) {
System.out.print("* ");
}
System.out.println();
}
}}
class Diamond extends PatternInputFromUser {
public void Logic() {
sc = new Scanner(System.in);
System.out.println("Enter the number of rows (odd number): ");
rows = sc.nextInt();
if (rows % 2 == 0) {
System.out.println("Please enter an odd number of rows.");
return;
}
System.out.println("Here is the Pattern in the Diamond format");
int spaces = rows / 2;
int stars = 1;
for (int i = 1; i <= rows / 2 + 1; i++) {
for (int j = 1; j <= spaces; j++) {
System.out.print(" ");
}
for (int j = 1; j <= stars; j++) {
System.out.print("*");
}
System.out.println();
spaces--;
stars += 2;
}
spaces = 1;
stars = rows - 2;
for (int i = 1; i <= rows / 2; i++) {
for (int j = 1; j <= spaces; j++) {
System.out.print(" ");
}
for (int j = 1; j <= stars; j++) {
System.out.print("*");
}
System.out.println();
spaces++;
stars -= 2;
}
}
}
class Triangle extends PatternInputFromUser {
public void Logic() {
sc = new Scanner(System.in);
System.out.println("Enter the number of rows: ");
rows = sc.nextInt();
System.out.println("Here is the Pattern in the Triangle format");
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= rows - i; j++) {
System.out.print(" ");
}
for (int j = 1; j <= i * 2 - 1; j++) {
System.out.print("*");
}
System.out.println();
}
}}
class InvalidChoice extends Exception {
public InvalidChoice() {
System.out.println("Invalid choice. Please choose 1 to 5.");
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int choice;
System.out.println("Choose the type of rectangle:");
System.out.println("1. Hollow Rectangle");
System.out.println("2. Solid Rectangle");
System.out.println("3. Half Pyramid");
System.out.println("4. Diamond");
System.out.println("5. Triangle");
choice = sc.nextInt();
if (choice < 1 || choice > 5) {
try {
throw new InvalidChoice();
} catch (InvalidChoice e) {
System.out.println(e + " Exception Occurs!");
}
}
switch (choice) {
case 1:
HollowRectangle hollowRectangle = new HollowRectangle();
hollowRectangle.Logic();
break;
case 2:
SolidRectangle solidRectangle = new SolidRectangle();
solidRectangle.Logic();
break;
case 3:
HalfPyramid halfPyramid = new HalfPyramid();
halfPyramid.Logic();
break;
case 4:
Diamond diamond = new Diamond();
diamond.Logic();
break;
case 5:
Triangle triangle = new Triangle();
triangle.Logic();
break;
default:
System.out.println("Something is wrong in your selection.");
}
}
}
OUTPUT
CONCLUSION
In summary, the "Interactive Java Pattern Generator" project successfully provides a user-
friendly platform for creating geometric patterns. Through systematic development phases, it
ensures functionality, usability, and performance. The application serves as a valuable tool for
education, creativity, and practical applications, demonstrating the power of Java programming
in solving real-world problems. Continuous improvement can further enhance its features and
relevance in various domains.
REFERENCE
https://www.geeksforgeeks.org/interfaces-and-inheritance-in-java/
https://www.javatpoint.com/exception-handling-in-java