2

I have a program that receives an array. I want to have it organize the results into ranges (like 60-69). It also needs to know how many of the numbers it received fit into which ranges so it can put them in accordingly. The way I've seen to create tabs in a table is

System.out.print("Column1/tColumn2");

How do you go about organizing the array data into a range? Do you specify it with a bunch of IF statements? And I assume you use a counter to tally up how many numbers fit into which ranges?

EDIT: Here's the code at present.

import java.util.Scanner;
import java.lang.Integer;
import java.lang.String;

public class Salary {
int salary;
int sales;

public static void main(String[] args) {
   Scanner input = new Scanner ( System.in );
   int Salary;
   Salary salary = new Salary();

   System.out.print( "Please enter the amount each employee brought in:");  
   String sales = input.nextLine();
   String salesArray[] = sales.split(" ");


   for(int i=0; i<salesArray.length; i++){
   Integer myInt = Integer.parseInt(salesArray[i]);

   System.out.print(salesArray[i] + " ");
   if (Integer.parseInt(salesArray[i]) <= 0) {
   System.out.println("Please enter a value greater than zero");}
   else {
   Salary = ((myInt/100) * 9) + 200;
   System.out.print(Salary); }
   }

   int two = 0;  //declared a variable, starting it at 0 and intending to increment it
                 //with input from the array

   System.out.print("Range/t#ofEmployees");
   for(int i=0; i<salesArray.length; i++) {
   if (salesArray[i] <= 200){}  //Error on the if statement, using the wrong operand
   else{ two++;}      //Attempt at the table and increment. 

   }

}

}
4
  • 1
    if you can't find an approach, take some random dummy data, and solve this problem by hand on a piece of paper with that dummy data ... while you do that write down what you do ... then try to formalize those steps Commented Sep 30, 2011 at 21:33
  • 2
    "I want to have it organize the results into ranges (like 60-69)" could you explain that a bit more? Commented Sep 30, 2011 at 21:35
  • i think the task is to aggregate scalar values into groups counters ... 5 events where the value is between 60 and 69 ... 16 events where the value is between 70 and 79 ... etc Commented Sep 30, 2011 at 21:39
  • 1
    Its so much easier using a hash table!! :D, but it depends if he learned that yet Commented Sep 30, 2011 at 21:45

1 Answer 1

2

i won't post an implementation, since this is homework, but think of this:

your array can be sorted ...

you can itterate that array, and count something up if the current value is less than a certain boundary ... once it is greater you can print one range and startover for the next range ...

boundaries can change from range to range ...

Sign up to request clarification or add additional context in comments.

1 Comment

Also note that Java has built-in sorting methods (for collections or arrays)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.