answersLogoWhite

0

taking an introductory Computer Science Class, this program that I wrote recently may help you. Basically it asks the user to input a bunch of numbers (1-100). Then, it places the numbers into categories of either 1-10,11-20,21-30, etc. Each "*" represents 5 elements. This program isn't as efficient.. but then again , it it's an introductory Computer Science Class, it'll work and at least give you a sense of direction!

/**

*Design and implement an application that reads a set of integer values in the range of 1 to 100 from the user and

then creates the chart showing how often the values appeared. The chart should look like the one shown below.

It shows how many values fell in the range from 1 to 10, 11 to 20, and so on. Print an asterisk for every five

values in each category. For example, if a category had 17 values, print three asterisks in that row. If a

category had 4 values, do not print any asterisks in that row. Be sure to include two classes StarTable and

StarTablePrgm. Feel free to make the input/output more user friendly.

*/

import java.util.ArrayList;

import java.util.Scanner;

//Margaret Wang creates StarTable Program

public class StarTable

{

private ArrayList<Integer> setOfInt;

//Default Constructor

public StarTable()

{

setOfInt = new ArrayList<Integer>();

}

//Method to read and add the set of integer values

public void addValues()

{

Scanner in = new Scanner(System.in);

System.out.println("Input an integer (1-100). Press enter to input it into the Array. Enter Q to stop adding: ");

String userInput = in.next();

while ( !(userInput.equalsIgnoreCase("Q")))

{

int addInt = Integer.parseInt(userInput);

setOfInt.add(addInt);

userInput = in.next();

}

}

public String printTable()

{

//counts how many numbers fit into each row

int count1 =0;

int count2=0;

int count3=0;

int count4=0;

int count5=0;

int count6=0;

int count7=0;

int count8=0;

int count9=0;

int count10=0;

//searches for the numbers that fit in the ranges

for (int i = 0; i < setOfInt.size(); i++)

{

if (setOfInt.get(i) <= 10)

{

count1++;

}

else if (setOfInt.get(i) <= 20)

{

count2++;

}

else if (setOfInt.get(i) <= 30)

{

count3++;

}

else if (setOfInt.get(i) <= 40)

{

count4++;

}

else if (setOfInt.get(i) <= 50)

{

count5++;

}

else if (setOfInt.get(i) <= 60)

{

count6++;

}

else if (setOfInt.get(i) <= 70)

{

count7++;

}

else if (setOfInt.get(i) <= 80)

{

count8++;

}

else if (setOfInt.get(i) <= 90)

{

count9++;

}

else if (setOfInt.get(i) <= 100)

{

count10++;

}

else

throw new IllegalArgumentException("You have entered an integer that cannot counted");

}

//Creates the Table

String table = "";

for (int a = 0; a < 10; a++)

{

table += a*10 + 1 + "-" + (a+1)*10 + "|";

if (a 9)

{

for (int j = 0; j < count10/5; j++ )

table += "*";

}

table += "\n";

}

return table;

}

}

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

Who make Java Program?

Many people make Java programs, but if you mean who invented the Java programming language it was James Gosling of Sun Microsystems.


When did James gosling make the java programming language?

1995


How can we make sure (pragmatically) that a class will have no further child classes. Which programming stmt will do this in Java and C?

How can we make sure (pragmatically) that a class will have no further child classes. Which programming stmt will do this in Java and C++?


What programming language are java applets written in?

Java applets are written in the Java programming language. Java is considered to be one of the oldest and most commonly used programming languages in the world.


What is the first name before of the Java Programming?

The first name of the Java Programming was Oak. It then went by the game Green and finally Java from Java coffee.


What is maintainability in Java?

In programming in general - and that would include Java - that means that you can make corrections and other changes, with a reasonable effort.


What is called OR in Java programming?

If you are going to make an if statement with or, use: Isn't that easy!


What is java card?

Java Card is a Java platform for programming smart cards.


Is java DBMS?

no, Java is not dbms.. Java is a programming language Dbms is database


Is the best institute for learn java programming in Pakistan?

The Java programming language is a general-purpose computer programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible. Then you learn java programming language in Pakistan get the best java programming classes at the lowest cost.


Can someone be hacking your system with Java?

Java is a programming language, you can use ANY programming language to make exploits to ... exploit one's system. As of today, I have seen numerous amounts of ways to be infected by Java. For example, the java drive by. If you click run, it will start loading a virus onto your computer.


What is the pane in which the Java programming statements are located called?

The pane in which the Java programming statements are located is called

Trending Questions
In which step of the opsec process do you select and implement tentative opsec measures? Which software program is used to analyze qualitative data? An author is most likely to defend her choice of multiple regression statistical techniques in which section of a proposal? What is the average class size at UCSD? What is the average IQ for a 21 year old? A special variable that receives a piece of data when a module is called? How do you pull out one or more pieces of a pie chart for emphasis? What is the importance pie chart? My blood lab result for MPV was 11.2 which had the word Hi next to it. Is this something I should be worried about? Franklin rolls a pair of six-sided fair dice with sides numbered 1 through 6. The probability that the sum of the numbers rolled is either even or a multiple of 5 is . The probability that the sum of? What conclusions you can you draw about the society of Jericho from looking at this illustration of the city? What is the Y axis called line graph? Is a 10 stone 11-year-old overweight? What is the probability to roll a 5? If the probability that an event will occur is three eighths then what is the probability that the event will not occur on the first trial and not occur on the second trial? What is 4.8737 rounded to the nearest thousandths? What number represents the digit in the hundreds place of the number 1098? What types of data tables are available? How much is 84 percentile equals mean plus 1 standard deviation or mean plus 1.4 standard deviation. Can you give me reference also please? Who discovered 6 sided dice?