Results 1 to 6 of 6
Thread: Help with histogram
- 11-02-2011, 02:30 AM #1
Member
- Join Date
- Nov 2011
- Posts
- 12
- Rep Power
- 0
Help with histogram
I'm currently trying to learn Java and my current assignment is to draw a histogram while using a separate class. I currently have
in my class andJava Code:public class Histogram { private int heightSeriesA; private int heightSeriesB; private int heightSeriesC; private int heightSeriesD; public int getHeightSeriesA (){ return heightSeriesA; } public void setHeightSeriesA (int A){ } public int getHeightSeriesB (){ return heightSeriesB; } public void setHeightSeriesB (int B){ } public int getHeightSeriesC (){ return heightSeriesC; } public void setHeightSeriesC (int C){ } public int getHeightSeriesD (){ return heightSeriesD; } public void setHeightSeriesD (int D){ }in my main. I don't think I need to have those "heightA" strings, but I wasn't sure.Java Code:Histogram one = new Histogram(); String heightA = ""; String heightB = ""; String heightC = ""; String heightD = ""; String A = "Enter height for A"; String B = "Enter height for B"; String C = "Enter height for C"; String D = "Enter height for D"; String titleheader = "Series height"; heightA = JOptionPane.showInputDialog(null, A, titleheader, 3); heightB = JOptionPane.showInputDialog(null, B, titleheader, 3); heightC = JOptionPane.showInputDialog(null, C, titleheader, 3); heightD = JOptionPane.showInputDialog(null, D, titleheader, 3);
The histogram needs to make an "*" above each letter in a vertical pattern above each letter based off the user input. (Yes, the dialog boxes and separate class and methods must be used). My main question is: Where do I go from here?
Sorry for this post being huge, but I tried to put hide tags around it, but it didn't seem to work.
- 11-02-2011, 02:49 AM #2
Re: Help with histogram
Your question is extremely vague. I could provide you with an infinite number of responses. Which one do you want?
- 11-02-2011, 02:54 AM #3
Member
- Join Date
- Nov 2011
- Posts
- 12
- Rep Power
- 0
Re: Help with histogram
Sorry, I guess if I rephrased my question it would be how to draw the histogram itself. Like, how to use the class with the instance variables in the main class to draw it.
- 11-02-2011, 03:03 AM #4
Re: Help with histogram
Where should the Histogram be drawn? I imagine in the Histogram class otherwise what would the point of it be. So you need a method that will use a loop heightA times and prints a star, repeat for heightB etc.
- 11-02-2011, 03:10 AM #5
Member
- Join Date
- Nov 2011
- Posts
- 12
- Rep Power
- 0
Re: Help with histogram
I think the histogram needs to be drawn in the main class. The reason the other class is there is to give the students in the course practice on calling methods from other classes.
So if I do draw it in the main class, I would still use the loops, but what would be a good way to call those methods in the Historgram class?
- 11-02-2011, 03:51 AM #6
Re: Help with histogram
I would seek clarification. If all you do is use the Histogram class to store the variables then it is totally pointless.
In main method you get user input
Store input in Histogram class
Retrieve values from Histogram class
Draw histogram
Do you see the total pointlessness of steps 2 & 3. The main method already has the values. There is no need to store them elsewhere and then get them back again.
Similar Threads
-
so i need help finishing my histogram plz help
By cachico12 in forum New To JavaReplies: 1Last Post: 05-10-2011, 06:04 AM -
need help with name histogram
By cachico12 in forum New To JavaReplies: 1Last Post: 05-09-2011, 08:27 AM -
JAI Histogram error
By deepsri in forum Advanced JavaReplies: 0Last Post: 01-07-2011, 10:06 AM -
histogram
By little_man in forum New To JavaReplies: 4Last Post: 11-13-2010, 01:38 AM -
How to create a Histogram
By Devilsfutbol17 in forum New To JavaReplies: 4Last Post: 06-04-2008, 09:22 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks