Results 1 to 5 of 5
  1. #1
    sebbybey is offline Member
    Join Date
    Aug 2008
    Posts
    5
    Rep Power
    0

    Default Arrays and Histogram Help Needed

    Histogram

    Using the following skeleton of code create a Java class and eventually a teest driver which displays a histogram using asterisks (*) – see the sample run below for an illustration of how it should look.


    public class Histogram {
    //Declare here an integer array. The size of the array will be determind within the getData method
    //Declare an interger to repersent the size of the array



    public void getData(){
    /*this method should ask the user how many elements the array should have, i.e. the size of
    * the array
    * Then the user must be asked to enter the values of the array
    * Finally it should call the displayData method passing as an argument the array that it was
    * just filled
    */

    }

    @SuppressWarnings(//need to fil) {
    private void displayData(){
    /*This method recieves the array and then displays on individual lines the message value at
    * position followed by the position (index) of array, then the actual value that it was
    * entered by the user for the position and thn as many asterisks as the value at that position
    * so if the value at a postion is 5 then expect to see five * asterisks
    */
    }



    }

    Here is the sample run

    Please enter size of array:
    5
    Please enter value at position 0
    1
    Please enter value at position 1
    4
    Please enter value at position 2
    6
    Please enter value at position 3
    4
    Please enter value at position 4
    2
    value at position 1*
    value at position 4****
    value at position 6******
    value at position 4****
    value at position 2**


    --------------------------

    Question 2

    You are given the following code. The code would not compile since there are syntactical errors and logical error(s) Fix the code.

    public class Addtime {

    public static void main(string[ ] args) {
    int min1, min2;
    int sec1, sec2;
    int secSum, minSum, hrSum;
    for (int i=0, i<6, i++) {
    System.out.println(“Enter the minutes for time 1: ”);
    Min1=EasyIn.getIn();
    System.out.println(“Enter the minutes for time 1: ”);
    sec1=EasyIn.getIn();
    System.out.println(“Enter the minutes for time 2: ”);
    min2=EasyIn.getIn();
    System.out.println(“Enter the minutes for time 2: ”);
    Sec2=EasyIn.getIn();
    secSum = sec1 + sec2 % 60;
    minSum = ((min1 + min2) + ((sec1 +sec2) / 60) % 60);
    hrSum= ((min1 + min2) + ((sec1 + sec2) / 60)) / 60;
    System.out.println(“The sum of the time is: ” + hrSum “:” + minSum + “:” + secSum;

    }
    }

    When you have fixed the error you can run it. A sample run is shown below.

    Enter the minutes for time 1:
    12
    Enter the minutes for time 1:
    12
    Enter the minutes for time 1:
    12
    Enter the minutes for time 1:
    12
    The sum of the times is: 0:24:24
    Enter the minutes for time 1:
    59
    Enter the minutes for time 1:
    1
    Enter the minutes for time 1:
    2
    Enter the minutes for time 1:
    0
    The sum of the times is: 1:1:3
    Enter the minutes for time 1:

    Send me an Email to sebbybey@msn.com

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,548
    Rep Power
    23

    Default

    Do you have a programming question?

    This looks like a homework assignment.

  3. #3
    sebbybey is offline Member
    Join Date
    Aug 2008
    Posts
    5
    Rep Power
    0

    Default

    yeah, somebody wanted me to give an assignment, and needed some answers if possible.

    I will really appreciate if you assist. Thanks in advance

  4. #4
    sebbybey is offline Member
    Join Date
    Aug 2008
    Posts
    5
    Rep Power
    0

    Default

    i'm teaching my self Java. I need to know more. Can you help

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    If you have an idea, it is best to try first and post your best attempt before giving up. If you have no clue whatsoeverl, then you should start with the basic Sun tutorials and work through them step by step. Good luck.

Similar Threads

  1. Help on Arrays...
    By cuellar14 in forum New To Java
    Replies: 4
    Last Post: 07-25-2008, 08:16 PM
  2. How to create a Histogram
    By Devilsfutbol17 in forum New To Java
    Replies: 4
    Last Post: 06-04-2008, 09:22 PM
  3. Arrays
    By bunbun in forum New To Java
    Replies: 1
    Last Post: 04-09-2008, 02:24 AM
  4. Help needed with java arrays code
    By d24706 in forum New To Java
    Replies: 2
    Last Post: 03-07-2008, 01:11 AM
  5. 2D-Arrays
    By kbyrne in forum New To Java
    Replies: 1
    Last Post: 02-07-2008, 10:08 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
  •