-
Array and number of occurences
Hi, i'm sorry but i'm new and poor at java.
I have to create a program that takes sample data such and counts the number of occurrences of each number in each sample data such as
1 5 3 4 5 5 5 4 3 2 5 5 5 3 or
2 3 4 5 6 7 8 9 0 2 3 5 6 8 8 8 9 4 5
and make the output as:
0 - 0
1 - 1
2 - 1
3 - 3
4 - 2
5 - 7
6 - 0
7 - 0
8 - 0
9 - 0
or
0 - 1
1 - 0
2 - 2
3 - 2
4 - 2
5 - 3
6 - 2
7 - 1
8 - 4
9 - 2
i also have to make the main method in a seperate file of the class, while using a Scanner. Can anyone help me? Even if it's just the beginning of the code?
-
The place to start is thinking about and deciding on how your program will work. You have three "functions" to perform: Getting the data (from user or file or random generation or whatever, the basic functionality should not matter); analyzing the data (occurrence count); and displaying the data.
I am a little confused by the "main method in a separate file of the class" phrase. Are you supposed to be writing 2 classes - one being the black box into which you send your data and out comes the analysis, with all of the interaction with the user being performed in a "driver" class? Anyway... this is where you would use Scanner to create an object which will accept the input stream of your choosing and put the data of the correct type into the container that will store it. Your driver would then dispatch the contents of the container to your occurrence analysis class, which might return a properly formatted string for your driver class to hold and then display to the console when requested.
-
I have the same question as nspils . What do you mean by "main method in a seperate file of the class". In any case, to be object oriented, you can write two different classes. One will be to get the input & sort it as per your requirement and return back the result. One to scan & get the input.
Go through the entire collection classes and try to pick up the correct collection class which you will be using. Please don't reinvent the wheel.
Once you are decided with the above points, start writing the code.
Hope this helps.
Similar Threads
-
Replies: 26
Last Post: 12-01-2012, 04:12 AM
-
By leospyder in forum Java
Replies: 2
Last Post: 04-12-2006, 08:14 AM
-
Replies: 6
Last Post: 11-01-2005, 09:05 AM
-
By kanakatam in forum Java
Replies: 2
Last Post: 04-15-2005, 09:06 PM
-
Replies: 3
Last Post: 01-11-2001, 11:29 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks