or this project, create a java program that includes the main method and three o
ID: 3771194 • Letter: O
Question
or this project, create a java program that includes the main method and three other methods. These methods can all be part of the same class or you can create a separate class for the three methods listed below (optional). The lab activity Hello World with Class demonstrates this approach. Here are the three methods that are required in addition to the main method.
drawLine: This method will display a line using asterisks
drawRectangle: This method will display a rectangle using asterisks
drawTriangle: This method will display a triangle using asterisks
The main method should display a label and call (activate) each method to display each shape. For example, the main method should display the label "Triangle", then display a triangle shape made of asterisks.
Then, the main method should display a label and call the methods again, but in a different order so the combined shapes make the more complex shapes. The labels should be: pine tree, house and beaker. Do not create a separate method for each complex shape. Instead, you must call one or more of the drawLine, drawRectagle and/or drawTriangle methods necessary to create these complex shapes.
The output must look like the example below:
Minimum Requirements:
1. This program must contain a total of four methods including main as described above. You can only use System.out.println statements in the methods. (10 points)
Important Note: If you decide to use an example from the Internet for this, you must modify the example to remove any extra code (loops, for, do, while, if, switch etc) so that the functions contain only System.out.println statements and organize the code into the required methods.
2. The main method should display the labels for each shape as shown in the example output, then call (activate) each method as needed, so the functions display the desired shapes. Follow the display order shown on the example output. (10 points).
Upload your .java file here
Explanation / Answer
PROGRAM:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author MDR
*/
import java.io.*;
public class Shape {
public static void main(String[] args)throws IOException
{
System.out.println("pine tree");
drawTriangle();
System.out.println();
System.out.println(" *");
System.out.println(" *");
System.out.println(" *");
System.out.println("house");
System.out.print(" ");
drawLine();
drawTriangle();
drawLine();
drawRectangle();
drawLine();
System.out.println("beaker");
drawLine();
System.out.println("* *");
drawRectangle();
}
static void drawTriangle()
{
System.out.println(" *");
System.out.println(" * *");
System.out.println(" * *");
System.out.print("*******");
}
static void drawLine()
{
System.out.println("**********");
}
static void drawRectangle()
{ System.out.println("*******");
System.out.println("* *");
System.out.println("* *");
System.out.println("* *");
System.out.print("*******");
}
}
OUTPUT:
pine tree
*
* *
* *
*******
*
*
*
house
**********
*
* *
* *
*****************
*******
* *
* *
* *
*****************
beaker
**********
* *
*******
* *
* *
* *
*******
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.