Kar Man

+ Follow
since Jun 16, 2018
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Kar Man

John Joe wrote:please post convertToGreyScale code

Here is my code for that method:
3 years ago

John Joe wrote:Why this line ?

The calling method must catch the IllegalArgumentException thrown from the getImageList() method, display the message, and exit, so that's why I implemented this!
3 years ago
Hi all, I am having issues with calling one of my methods, specifically displayImage(). I am supposed to use this program to convert an image from a file to grey scale, high contrast, or negative based on user input. User input is also prompted to ask the user which image they would like to convert. This is the code thus far:

My main problem is with calling the displayImage() method -- the methods that come after that can actually be ignored for now. I am using the DrawingPanel.java (https://www.buildingjavaprograms.com/DrawingPanel.java) ImageInfo.java, which is

I am not sure if you need that information to solve this question, because again, my main problem is the method not being called, and not knowing how to initialize ImageInfo image in the main method of the program. Thank you in advance for any insight on this.
3 years ago
Hi, in the case that I want to throw an exception when the wrong type of data type is entered, how can I do this with IllegalArgumentException?

For instance, if someone were to enter a double, string, or boolean input into the scanner instead of an integer, how could I throw an exception for this? I have to do this for an assignment, and they specifically said that I need to use a throw exception for this. Thanks everyone in advance!
3 years ago
home / study / engineering / computer science / computer science questions and answers / in java, i need to create a program that draws a design made up of 1 - 5 rows of equilateral ...
Your question has been answered
Let us know if you got a helpful answer. Rate this answer
Question: In Java, I need to create a program that draws a design made up of 1 - 5 rows of equilateral tria...
In Java, I need to create a program that draws a design made up of 1 - 5 rows of equilateral triangles. The length of each side of a triangle is 100 pixels. Each row will contain one more triangle than the row above it. The triangles are contiguous and the lower left/right points of each triangle form the uppermost points of the triangles in the row below. The (x, y) coordinates of the topmost point of the triangle in the first row must be (300, 50). The user will create a custom color for the design by specifying the amount of red, green, and blue used to draw it. The user will also specify the number of rows of triangles. The image of what the output is supposed to look like is given here: https://stackoverflow.com/questions/50886251/draw-equilateral-triangles-using-a-nested-for-loop/50886556?noredirect=1#comment88774796_50886556

The program must be named Triangle and use the DrawingPanel class provided by the textbook to create a drawing panel (canvas) with a width of 600 pixels and an height of 600 pixels and then draw the triangle design. Prompt the user for a number of rows between 1 and 5 for the triangle design. Convert numbers below 1 to 1 and numbers above 5 to 5. Then prompt the user for the Red, Green, and Blue values used to create the custom color for the design. These values should be between 0 and 255 – convert numbers below 0 to 0 and numbers above 255 to 255 (I am not sure how to convert to these specific values?). I know that I need to import the java.util and java.awt packages to run my program. The console should look like this:

$ java Triangle

Number of Rows(1-5): 5
Red value (0-255): 255
Green value (0-255): 5
Blue value (0-255): 5

*CLOSE the Drawing Panel to exit the program*

An example of what the output of the program should look like is also attached.

In addition, if the user enters something other than an integer value (such as a double or a string), the program will throw an exception.

So far, I have tried to use Pythagorean theorem to figure out the coordinates of the points of the triangle.
My coordinates are such that for an equilateral triangle:

Top point of triangle: (x, y)

Coordinates of lower left point: (x - len/2, y + len * sqrt(3)/2)

Coordinates of lower right point: (x + len/2, y + len * sqrt(3)/2)

I have attached what an individual triangle is set up as well.

I want to use the the method drawTriangle in addition the to the main method, such that it looks like this:

//Draws an equilateral triangle with topmost point at (x,y) with the given side length and color
public static void drawTriangle(Graphics g, Color color, int x, int y, int sideLength) {


The main method should use a nested for loop to draw triangles (using an iterative approach, not a recursive approach). I am only to use java.awt and java.util. The code I have so far is

I am having trouble with the nested for loop in the main method. I feel like I have mastered the scanner part of the code in the main method, however. Also, I am not confident in the drawTriangle method that I have. I believe the proper header should be drawTriangle(Graphics g, Color color, int x, int y, int sideLength).
3 years ago