IN JAVA
Overview
In this project you will implement a Java program that will print several shapes and patterns according to uses input. This program will allow the use to select the type (say, rectangle, triangle, or diamond), the size and the fill character for a shape. All operations will be performed based on the user input which will respond to a dynamic menu that will be presented. Specifically, the menu will guide the user to decide between different forms to print in text mode. The forms to select from will be rectangle, triangle. and diamond. Additionally. there will be a pattern to print which will be explained later in this document. The size of the form/pattern will be also determined by the user which will be validated to be complying with specific values depending on the form.
Description
This section describes as detailed as possible all the options that need to be accomplished in the project.
Main Method
The main method must print as the first line of output
Project 2: Developed by John Smith
Note that you should replace the text John Smith with your name. It will then call getMenuSelection() to start the rest of the operations of this program.
Menu Options
The menu should be implemented with two methods:
Please, select one of the following options 0. Exit 1. Print a Rectangle 2. Print a Triangle 3. Print a Diamond 4. Print a Pattern
Rectangle Shape
You should implement the following three methods to print a rectangle shape.
Triangle Shape (Using Nested Loops)
You should implement the following two methods to print a triangle shape.
Diamond Shape
You should implement the following three methods to print a diamond shape.
Pattern Shape (Using Nested Loops)
You should implement the following two methods to print a triangle shape.
9 8 7 6 5 4 3
8 7 6 5 4 3
7 6 5 4 3
6 5 4 3
5 4 3
4 3
3
Sample Input/Output
Please refer to this link for sample input/output expected of this program.
Rubric
JAVA CODE
package miscellaneous;
import java.util.Scanner;
public class console {
public static void makeRectangle(Scanner scnr) {
System.out.println("Enter Length:
");
int length = scnr.nextInt();
int width =0;
while(true) {
System.out.println("Enter Width: ");
width =
scnr.nextInt();
if(width<=0
|| width>80) {
System.out.println("Invalid
Width(max->80)");
continue;
}
else {
break;
}
}
System.out.println("Enter fill
character: ");
char c =
scnr.next().charAt(0);
System.out.println("Fill or not
fill(y/n): ");
String f = scnr.next();
if(f.equals("y")) {
printRectangle(length,width,c,false);
}
else {
printRectangle(length,width,c,true);
}
}
public static void printRectangleLine(int size, char
fillChar, Boolean hollow) {
if(!hollow) {
for(int
i=0;i<size;i++) {
System.out.print(fillChar);
}
System.out.println();
}
else {
for(int
i=0;i<size;i++) {
if(i==0 || i==size-1) {
System.out.print(fillChar);
}
else {
System.out.print(" ");
}
}
System.out.println();
}
}
public static void printRectangle(int length, int
width, char fillChar, Boolean hollow) {
if(hollow) {
for(int
j=0;j<length;j++) {
if(j==0 || j==length-1) {
printRectangleLine(width,fillChar,!hollow);
}
else {
printRectangleLine(width,fillChar,hollow);
}
}
}
else {
for(int
j=0;j<length;j++) {
printRectangleLine(width,fillChar,hollow);
}
}
}
static void makeTriangle(Scanner scnr) {
int width=0;
while(true) {
System.out.println("Enter Width: ");
width =
scnr.nextInt();
if(width<=0
|| width>80) {
System.out.println("Invalid
Width(max->80)");
continue;
}
else {
break;
}
}
printTriangle(width);
}
public static void printTriangle(int width) {
for(int i=1;i<width;i++)
{
for(int j=i;j<width;j++)
{
System.out.print(" ");
}
for(int j=1;j<=(2*i-1);j++)
{
if(j==1) {
System.out.print("/");
}
if(j==(2*i)-1) {
System.out.print("\\");
}
else {
System.out.print(" ");
}
}
System.out.println("");
}
for(int i=0;i<width*2;i++)
{
System.out.print("_");
}
}
static void printDiamond(Scanner scnr) {
int size =0;
while(true) {
System.out.println("Enter size: ");
size =
scnr.nextInt();
if(size<=0 ||
size>80) {
System.out.println("Invalid
size(max->80)");
continue;
}
else {
break;
}
}
System.out.println("Enter edge
char: ");
char echar =
scnr.next().charAt(0);
System.out.println("Enter fill
char: ");
char fillchar =
scnr.next().charAt(0);
printDiamond(size,echar,fillchar);
}
public static void printNChars(int n, char c){
for(int i=0;i<n;i++) {
System.out.print(c);
}
}
public static void printDiamond(int size, char
edgeChar, char fillChar) {
int i,j;
int space=size-1;
for (j = 1; j <= size;
j++)
{
printNChars(space,' ');
space--;
System.out.print(edgeChar);
printNChars(2*j-3,fillChar);
if(2*j-3!=-1) {
System.out.print(edgeChar);
}
System.out.println("");
}
space = 1;
for (j = 1; j <= size - 1; j++)
{
printNChars(space,' ');
space++;
System.out.print(edgeChar);
printNChars(2*(size-j)-3,fillChar);
if(2*(size-j)-3!=-1) {
System.out.print(edgeChar);
}
System.out.println("");
}
}
static void printPattern(Scanner scnr) {
int num1=0,num2=0;
String asc="";
while(true) {
System.out.println("Enter num1: ");
num1 =
scnr.nextInt();
if(num1<0 ||
num1>9) {
System.out.println("Invalid value! Must be
between 0-9(inclusive).\nEnter again:");
continue;
}
break;
}
while(true) {
System.out.println("Enter num2: ");
num2 =
scnr.nextInt();
if(num2<0 ||
num2>9) {
System.out.println("Invalid value! Must be
between 0-9(inclusive).\nEnter again:");
continue;
}
break;
}
if(num1>num2) {
int
temp=num1;
num1=num2;
num2=temp;
}
while(true) {
System.out.println("Ascending triangle?(y/n):");
asc =
scnr.next();
if(asc.equals("y") || asc.equals("n")) {
break;
}
else {
System.out.println("Invalid Input.Enter either y
or n: ");
continue;
}
}
if(asc.equals("y")) {
printPattern(num1,num2,true);
}
else {
printPattern(num1,num2,false);
}
}
public static void printPattern(int num1, int num2,
Boolean ascending) {
if(ascending) {
int c=0;
for(int
i=num1;i<=num2;i++) {
for(int j=num2;j>=num2-c;j--) {
System.out.print(j+"
");
}
c+=1;
System.out.println();
}
}
else {
int c=0;
for(int
i=num2;i>=num1;i--) {
for(int k=0;k<c;k++) {
System.out.print(" ");
}
for(int j=num2-c;j>=num1;j--) {
System.out.print(j+"
");
}
System.out.println();
c+=1;
}
}
}
static void printMenu() {
System.out.println("Please select
one of the following options : ");
System.out.println("0.Exit");
System.out.println("1.Print a
Rectangle");
System.out.println("2.Print a
Triangle");
System.out.println("3.Print a
Diamond");
System.out.println("4.Print a
Pattern");
}
static void getMenuSelection() {
Scanner sc = new
Scanner(System.in);
while(true) {
printMenu();
int choice =
sc.nextInt();
if(choice==0)
{
System.out.println("Thank you for using this
program, Good bye!");
break;
}
if(choice==1)
{
makeRectangle(sc);
continue;
}
if(choice==2)
{
makeTriangle(sc);
System.out.println();
continue;
}
if(choice==3)
{
printDiamond(sc);
continue;
}
if(choice==4)
{
printPattern(sc);
continue;
}
else {
System.out.println("Incorrect selection!Please
try again.");
continue;
}
}
}
public static void main(String[] args) {
System.out.println("Project
2:Developed by YOUR NAME");
getMenuSelection();
}
}
Screenshot of code








Sample Output






IN JAVA Overview In this project you will implement a Java program that will print several...
Hello Guys. I need help with this its in java In this project you will implement a Java program that will print several shapes and patterns according to uses input. This program will allow the use to select the type (say, rectangle, triangle, or diamond), the size and the fill character for a shape. All operations will be performed based on the user input which will respond to a dynamic menu that will be presented. Specifically, the menu will guide...
How can i print a diamond implementing these methods public static void printNChars(int n, char c)). This method will print n times the character c in a row, public static void printDiamond(int size, char edgeChar, char fillChar). This method will call printNChars() method to print the shape. It will use the edgeChar to print the sides and the fillChar to fill the interior of the shape. The shape will have a height and a width of the given size. public...
Python 3: Please follow the respective rubric
for the following function definition.
Rubric:
Rectangle Shape You should implement the following functions to print a rectangle shape. • print_rectangle(length, width, fillChar, hollow). This function will use draw_shape_line() function to print a rectangle shape with the given length and width, If the hollow is true, the shape will be hollow rectangle, otherwise a filled rectangle. This function must not interact with the user. For example, the call print_rectangle(5, 10, '*', False) should...
Hello, I need help writing the two methods to print a triangle shape in java. An example of the shape is as follows: 9 8 7 6 5 4 3 8 7 6 5 4 3 7 6 5 4 3 6 5 4 3 5 4 3 4 3 3 One method should be defined as "public static void printPattern(int num1, int num2, Boolean ascending)". This method will print a upper-triangle matrix-like layout filled will a sequence of integers...
JAVA Code Requried Copy the file java included below. This program will compile, but, when you run it, it doesn’t appear to do anything except wait. That is because it is waiting for user input, but the user doesn’t have the menu to choose from yet. We will need to create this. Below the main method, but in the Geometry class, create a static method called printMenu that has no parameter list and does not return a value. It will...
Write a C program that does the following: Displays a menu (similar to what you see in a Bank ATM machine) that prompts the user to enter a single character S or D or Q and then prints a shape of Square,Diamond (with selected height and selected symbol), or Quits if user entered Q.Apart from these 2 other shapes, add a new shape of your choice for any related character. Program then prompts the user to enter a number and...
in
java
M al you wille to print: • The area of the box if the user gives valid sizes "Invalid size given', otherwise . For example, if the user enters: 'small medium large', the program will print Area of the box is 6 . For example, if the user enters: 'small medium big', the program will print 'Invalid size given LAB ACTIVITY 31.24.1: Chapter 7: Area of a box (Methods) 0/5 Main.java Load default template. 1 import java.util.Scanner; LD...
Write a Python program in this Jupyter Notebook. This program will allow a user to choose from a menu to print various text shapes includeing rectangle, triangle, and diamond as well as a set of numbers in a pattern. This program will allow the user to select the type, the size and/or the fill character for a shape. Your program will verify user inputs such as size for certain range specifications, depending on the shapes.
Project Objectives: To develop ability to write void and value returning methods and to call them -- Introduction: Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing the smaller tasks (calling the methods) in the correct order. This also allows for efficiencies, since the method can...
Assignment: Write a program with each of the following methods. You can assume this program is saved in a file called multiArrays.java. A sample main method and sample output is provided at the end of this section. All arrays created are of integer-type. Write a method to declare, initialize, and populate a two-dimensional array. Using the following header: public static int[ ][ ] declare2D(Scanner scnr) The user will indicate the size of the array. Write a method to declare,...