jo jo

Greenhorn

Posts: 1

posted 13 years ago

Hi all~

It may be long but I am totally new to this java programming...

i will be thankful if any kind soul can help me out on this :

a)I wish to draw 7 rectangles in a window to show integer array. The height of the rectangle will represent the value of an element of an array. The first element of the array will be represented by the left-most rectangle. This could represent an array whose smallest element is the second to last and whose largest element is the fourth.

I would like to come out with a procedure that will take integer array as input and draw the 7 rectangles in a row. Assume that the all are of the same length (50 elements),and the values of the integers on the array will vary between 1 and 50. But can be improved further to make it work with different sizes of arrays and vary the width of rectangles with the number of elements in the array,and vary the computation of the heights depending on the range of values.

b)How do i implement new algorithms in java, using MergeSort and SelectSort as examples?

C)And a procedures that takes an int input,n, and generates an int array of n random ints with values between 1 and n.It will be better if you have the procedure ensure that no value appears more than once.

d)My last question is that are there ways to draw rectangles using different types of sorting proceduces? Adapt the algorithm so that it repaints the screen senibly : this will depend on the algorithm. My intention is to use the algorithm to sort out the arrays. Any ideas?

cheers!

It may be long but I am totally new to this java programming...

i will be thankful if any kind soul can help me out on this :

a)I wish to draw 7 rectangles in a window to show integer array. The height of the rectangle will represent the value of an element of an array. The first element of the array will be represented by the left-most rectangle. This could represent an array whose smallest element is the second to last and whose largest element is the fourth.

I would like to come out with a procedure that will take integer array as input and draw the 7 rectangles in a row. Assume that the all are of the same length (50 elements),and the values of the integers on the array will vary between 1 and 50. But can be improved further to make it work with different sizes of arrays and vary the width of rectangles with the number of elements in the array,and vary the computation of the heights depending on the range of values.

b)How do i implement new algorithms in java, using MergeSort and SelectSort as examples?

C)And a procedures that takes an int input,n, and generates an int array of n random ints with values between 1 and n.It will be better if you have the procedure ensure that no value appears more than once.

d)My last question is that are there ways to draw rectangles using different types of sorting proceduces? Adapt the algorithm so that it repaints the screen senibly : this will depend on the algorithm. My intention is to use the algorithm to sort out the arrays. Any ideas?

cheers!

Stan James

(instanceof Sidekick)

Ranch Hand

Ranch Hand

Posts: 8791

posted 13 years ago

Sounds like you have a bunch of problems to solve. Try one at a time!

I'd probably start by learning how to draw since I've never done Java drawing. Guessing that maybe I should draw four lines, maybe I'd make a method like this:

And I'd make a test program that can set up a drawing area and draw a rectangle:

Then I might deal with the array of heights ...

Then maybe scale the height so the tallest one always touches the top

Finally the sorting issue. If it's part of your assignment to write a sort, google for java sort algorithms. Bubble sort is far and away the easiest to understand and works fine for a small number of values. Quicksort is serious computer science stuff. You might copy the code from somewhere, but I wouldn't bother understanding it. You don't write fast sorts, you BUY them. And if you don't have to write your own, Java has some Collection types that sort, tho you'll have to use Integer objects instead of int natives.

I'm betting I'm wrong about how to draw rectangles and you'll find something in Java2D docs that already draws them nicely. But see if the progression of problem solving helps at all. Check in again when you have some code going - or not going.

I'd probably start by learning how to draw since I've never done Java drawing. Guessing that maybe I should draw four lines, maybe I'd make a method like this:

And I'd make a test program that can set up a drawing area and draw a rectangle:

Then I might deal with the array of heights ...

Then maybe scale the height so the tallest one always touches the top

Finally the sorting issue. If it's part of your assignment to write a sort, google for java sort algorithms. Bubble sort is far and away the easiest to understand and works fine for a small number of values. Quicksort is serious computer science stuff. You might copy the code from somewhere, but I wouldn't bother understanding it. You don't write fast sorts, you BUY them. And if you don't have to write your own, Java has some Collection types that sort, tho you'll have to use Integer objects instead of int natives.

I'm betting I'm wrong about how to draw rectangles and you'll find something in Java2D docs that already draws them nicely. But see if the progression of problem solving helps at all. Check in again when you have some code going - or not going.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi