• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to make Stem and plot in java ?

 
Greenhorn
Posts: 5
Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi Guys!

Usually I didn't ask for help in homeworks

but this semester I have like a hundreds of courses!

and this homework is very advance to me !








I didn't know actually how to start !

so please help me
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't see the image (firewall rules at work), but i can give you general advice.

1) Before you ever write a single line of code, write down on paper, in English, what you need to do. at first, use broad terms (read records, process data, print results). Then go back 4-5 times and revise it, each time making each line more specific, usually by breaking it into 2-3 (or more) additional steps.

2) When you start writing code, write the LEAST amount you can before you go back and compile/run/test. If you only add one line and you now get a logical error, you know exactly what line caused it. If instead you write 100 lines before you re-compile, you have a tough row to hoe.

3) try to write small, simple methods, and then build them up to your larger program. No single method should do much. For example, your main() method will probably not do much more than create an instance of your class and call its start() or run() method (which you will also write).
 
Sarah Noah
Greenhorn
Posts: 5
Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I created file data.txt contains :



and my teacher asked me to make what he call it

Stem and Leaf Plots

that's mean to order the numbers in the file like this :


Stem | Leaf | Frequency
------|---------------------------------------------|---------------------
0 | 02 15 19 47 71 75 82 92 96 | 9
1 | 16 17 23 38 40 59 61 94 | 8
2 | 01 16 41 59 | 4
3 | 07 53 76 | 3
4 | 75 | 1
-------|---------------------------------------------|---------------------
Total | | 25


^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I couldn't make it like the picture
Sorry!
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So how did you do that?

How do you go from your list of numbers to the graph? Tell us in ENGLISH. I'll even get you started

For example,

1) read the file with the numbers
2) count up how many go in each row
3) print out the results.

So now, you can work on each part separately.

another question to consider: Do you know your input range will always be between 0 and 5, or do you need to allow for the numbers to be between 0 and 100? or 10,000?

and honestly, before we even get that far, do you know how to write and compile java at all? Can you write a 'hello world' program, or do we need to start back there? Do you have the JDK installed?

It's easier for folk to help you if you tell us WHERE you are stuck, other than "I don't know what to do". The more specific you can be, the more likely you are to get the help you need.

 
Sarah Noah
Greenhorn
Posts: 5
Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


OK ,

could you tell me please how to "cut" what comes before decimal point in java

for instance 0.02

i want to "convert" it to (02)
 
Ranch Hand
Posts: 100
VI Editor Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sarah TheNice wrote:

OK ,

could you tell me please how to "cut" what comes before decimal point in java

for instance 0.02

i want to "convert" it to (02)



I am a rank beginner myself, so if I am mistaken I hope someone corrects me

To get (02) from 0.02 I would multiply 0.02 by 100 and then remove the integer part: divide by 100 and get the remainder using the modulo (%) operation:

0.02 * 100 = 2
2 % 100 = 2
to get 02 I would simply check that the number is less or equal to 9 and then pad it with the 0:

if x <= 9
then print "0" + x

Hope this helps.

 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sarah TheNice wrote:

OK ,

could you tell me please how to "cut" what comes before decimal point in java

for instance 0.02

i want to "convert" it to (02)


Are they Strings or Floats? Will there always be two digits to the right of the decimal point?
 
Sarah Noah
Greenhorn
Posts: 5
Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK,

after alot of thinking

i think i should create :

1- readInput() method


2- countTotal () method


3- findMax () method


4- findMin () method

3 and 4 should return 4.75 & 0.02

then

i will convert these Doubles to Int by e.g

int max1 = (int)max; >>>> this will return 4

then I don't know if i should make lastRow=4;
 
Ranch Hand
Posts: 96
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

To construct a stem plot, the observations must first be sorted in ascending order ...

(From Wikipedia)

Sounds like one of the things you should create a method for too, isn't it?

Wim
 
Ranch Hand
Posts: 73
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sarah,

Not sure about the function returning 2D array, because returning 2D array for each iteration makes no sense and a class level 2D array though possible, will be a wastage of memory as each iteration doesn't have the same frequency. I have implemented the solution below in hurry. The switch-case part is easy enough for you to implement.

Please note data.txt contains data separated by a space only!



The above solution gives the output as

0|02 15 19 47 71 75 82 92 96 |9
1|16 17 23 38 4 59 61 94 |8
2|01 16 41 59 |4
3|07 53 76 |3
4|75 |1
 
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You shouldn't give away the solution like that. Giving away the solution doesn't benefit anyone, in fact it is most likely a bad thing because posters will become dependent on answers from others inside of from themselves. Please consider removing your post.

Hunter
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The solution was deleted. We don't do that here.
 
Pranav Raulkar
Ranch Hand
Posts: 73
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys! sorry about that. I'm new here. I thought the problem was good, so I tried so wanted to help.
But I think that was just rude to delete the entire thing. You literally wasted my efforts to help Sarah.
Anyways, no discussion further and no hard feelings
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The issue was it wouldn't be helping Sarah.

Hunter
 
Sarah Noah
Greenhorn
Posts: 5
Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you so much Pranav
i really appreciate it
thanks to all of you guys


i wrote this code


but when i run it

it says

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 9
at Stemplots.main(Stemplots.java:32)


------------------
(program exited with code: 1)
Press return to continue


 
reply
    Bookmark Topic Watch Topic
  • New Topic