Write a program in Java Programming Language Object-oriented Programming Assignm
ID: 3713343 • Letter: W
Question
Write a program in Java Programming Language
Object-oriented Programming Assignment #6 Deadline: Tuesday, Apr. 24 1. Program to be implemented Simple Drawing Tool]) .A program that draws multiple shapes with a text-based menu 2. Overview Write a program that can draw shapes with a text-based menu. The target picture is as follows. (1) Line (2) Wide Horizontal Line (3) Rectangle (a space between symbols) S$$$ S$$$ (4) Square (5) Triangle Add several shapes which you want . Each shape can have an arbitrary character as a pattern. (6) ?? Define the necessary parameters for each shape (e.g., length for Line, width and height for Rectangle) When you start the program, the program shows the Drawing Tool menu. When you select one of the list in the menu, the program executes the expected function and returns to the menu. You can continue this process until you select Quit in the menu. The menu that you have to implement is as follows. (1) Draw Select one of the shapes, put the necessary parameters, and draw it. (2) Show All: Draw the shapes created so far one by one on the screen. (3) Delete All Delete all shapes created so far from the list. (4) Quit: Exit the program 3. Guidelines (1) Implement each class for each shape. At least, implement the following classes. ine WideHorizontal Line Rectangle Square .Triangle (2) Creates their parent class, Shape. Utilize the parent class. For example, you can create the print method in the Shape class to print out the information of each child class. (3) Define methods as many as possible for each class (4) Declare data as private. 1/2Explanation / Answer
Note : Just run the code in any ide or complier and follow instrustions you will get your desired output......Happy Coding!!
//////////////////////////////////////////////////////////////Shape.java/////////////////////////////////////////////////////////////////////
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Shape {
int Line_Length=0;
int Wide_Horizontal_Line_Length=0;
int Rectangle_Width=0,Rectangle_Height=0;
int Square_Sides=0;
int Triangle_Length=0;
public int getLine_Length() {
return Line_Length;
}
public void setLine_Length(int line_Length) {
Line_Length = line_Length;
}
public int getWide_Horizontal_Line_Length() {
return Wide_Horizontal_Line_Length;
}
public void setWide_Horizontal_Line_Length(int wide_Horizontal_Line_Length) {
Wide_Horizontal_Line_Length = wide_Horizontal_Line_Length;
}
public int getRectangle_Width() {
return Rectangle_Width;
}
public void setRectangle_Width(int rectangle_Width) {
Rectangle_Width = rectangle_Width;
}
public int getRectangle_Height() {
return Rectangle_Height;
}
public void setRectangle_Height(int rectangle_Height) {
Rectangle_Height = rectangle_Height;
}
public int getSquare_Sides() {
return Square_Sides;
}
public void setSquare_Sides(int square_Sides) {
Square_Sides = square_Sides;
}
public int getTriangle_Length() {
return Triangle_Length;
}
public void setTriangle_Length(int triangle_Length) {
Triangle_Length = triangle_Length;
}
public void DrawLine(){
for(int i=0;i<Line_Length;i++){
System.out.print("*");
}
System.out.println();
}
public void DrawHorizontialLine(){
for(int i=0;i<Wide_Horizontal_Line_Length;i++){
System.out.print("@ ");
}
System.out.println();
}public void DrawRectangle(){
for(int i=0;i<Rectangle_Height;i++){
for(int j=0;j<Rectangle_Width;j++){
System.out.print("#");
}
System.out.println();
}
}
public void DrawSquare(){
for(int i=0;i<Square_Sides;i++){
for(int j=0;j<Square_Sides;j++){
System.out.print("$");
}
System.out.println();
}
}
public void DrawTriangle(){
for(int i=0;i<Triangle_Length;i++){
for(int j=0;j<=i;j++){
System.out.print("X");
}
System.out.println();
}
}
public static void main(String[] args) {
List<Shape> ShowAll = new ArrayList<Shape>();
Scanner sc = new Scanner(System.in);
while(1>0){
System.out.println("Menu List:");
System.out.println("1: Draw");
System.out.println("2: ShowAll");
System.out.println("3: ClearAll");
System.out.println("4: Quit");
System.out.println();
System.out.println();
System.out.println("Please select the option:");
int option = sc.nextInt();
if(option==1){
System.out.println("Shape List :");
System.out.println("1: Line");
System.out.println("2: Wide Horizontial Line");
System.out.println("3: Rectangle");
System.out.println("4: Square");
System.out.println("5: Triangle");
System.out.println("Select the Shape that you want to draw?");
int draw = sc.nextInt();
if(draw ==1){
Shape line = new Shape();
System.out.println("Please select the line length :");
int length = sc.nextInt();
if(length>0){
line.setLine_Length(length);
line.DrawLine();
ShowAll.add(line);}
else{
System.out.println("Invaild length of the line must be greater than Zero....");
}
}
else if(draw==2){
Shape horizontialine = new Shape();
System.out.println("Please select the Horizontialine :");
int length = sc.nextInt();
if(length>0){
horizontialine.setWide_Horizontal_Line_Length(length);
horizontialine.DrawHorizontialLine();
ShowAll.add(horizontialine);
}
else{
System.out.println("Invaild length of the horizontial line must be greater than Zero....");
}
}
else if(draw==3){
Shape rectangle = new Shape();
System.out.println("please select the width of Rectangle :");
int width = sc.nextInt();
System.out.println("Please select the height of Rectangle :");
int height = sc.nextInt();
if(width>0 && height>0){
rectangle.setRectangle_Width(width);
rectangle.setRectangle_Height(height);
rectangle.DrawRectangle();
ShowAll.add(rectangle);
}
else{
System.out.println("Invaild Width or Height of the rectangle must be greater than Zero....");
}
}
else if(draw==4){
Shape square = new Shape();
System.out.println("Please select the sides of the Square:");
int side = sc.nextInt();
if(side>0){
square.setSquare_Sides(side);
square.DrawSquare();
ShowAll.add(square);
}
else{
System.out.println("Invaild side of the Square must be greater than Zero....");
}
}
else if(draw==5){
Shape triangle = new Shape();
System.out.println("Please select the height of the triangle :");
int height = sc.nextInt();
if(height>0){
triangle.setTriangle_Length(height);
triangle.DrawTriangle();
ShowAll.add(triangle);
}
else{
System.out.println("Invaild height of the triangle must be greater than Zero....");
}
}
else{
System.out.println("Opps you select Wrong Option!!");
}
}
else if(option==2){
System.out.println("Total no.of Drawings that you draw is : "+ShowAll.size());
for(Shape shape : ShowAll){
if(shape.getLine_Length()>0){
System.out.println("Line of length is :"+shape.getLine_Length());
shape.DrawLine();
}
else if(shape.getWide_Horizontal_Line_Length()>0){
System.out.println("Wide Horizontial line of length :"+shape.getWide_Horizontal_Line_Length());
shape.DrawHorizontialLine();
}
else if(shape.getRectangle_Width()>0 && shape.getRectangle_Height()>0){
System.out.println("Rectangle of Width :"+shape.getRectangle_Width()+" "+ "& Height is : "+shape.getRectangle_Height());
shape.DrawRectangle();
}
else if(shape.getSquare_Sides()>0){
System.out.println("Square of Sides :"+shape.getSquare_Sides());
shape.DrawSquare();
}
else if(shape.getTriangle_Length()>0){
System.out.println("Triangle of height :"+shape.getTriangle_Length());
shape.DrawTriangle();
}
}
}
else if(option==3){
ShowAll.clear();
System.out.println("you Cleared the Drawings that you Drew....");
}
else{
if(option==4){
System.out.println("You Quit the Game!! Bye.....");
break;
}
else
System.out.println("You Select the Wrong option!!...Lets Another Try...!!");
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.