Results 1 to 6 of 6
  1. #1
    Conan is offline Member
    Join Date
    Nov 2011
    Posts
    12
    Rep Power
    0

    Default 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
    Java 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 class and
    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);
    in my main. I don't think I need to have those "heightA" strings, but I wasn't sure.

    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.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,788
    Rep Power
    7

    Default Re: Help with histogram

    Your question is extremely vague. I could provide you with an infinite number of responses. Which one do you want?

  3. #3
    Conan is offline Member
    Join Date
    Nov 2011
    Posts
    12
    Rep Power
    0

    Default 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.

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,788
    Rep Power
    7

    Default 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.

  5. #5
    Conan is offline Member
    Join Date
    Nov 2011
    Posts
    12
    Rep Power
    0

    Default 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?

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,788
    Rep Power
    7

    Default 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

  1. so i need help finishing my histogram plz help
    By cachico12 in forum New To Java
    Replies: 1
    Last Post: 05-10-2011, 06:04 AM
  2. need help with name histogram
    By cachico12 in forum New To Java
    Replies: 1
    Last Post: 05-09-2011, 08:27 AM
  3. JAI Histogram error
    By deepsri in forum Advanced Java
    Replies: 0
    Last Post: 01-07-2011, 10:06 AM
  4. histogram
    By little_man in forum New To Java
    Replies: 4
    Last Post: 11-13-2010, 01:38 AM
  5. How to create a Histogram
    By Devilsfutbol17 in forum New To Java
    Replies: 4
    Last Post: 06-04-2008, 09:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •