Solved

How do i write this progrma

Posted on 2009-05-07
15
223 Views
Last Modified: 2013-11-23
I need to do the following write a program that would be  a number generator program that asks the user to input a file name, then goes on to generate 100 random integers and saves them in the aforementioned file THEN a program that reads a list of integers from a file into an array or some data structure - The TreeSet method was what i was using for this so that it would be easier to sort. The program should read the list thenusing a sorting algorithm of your choice (possible examples include quick sort) order the list. Once the list is ordered it should be saved to an output file. The program should prompt the user for an input and output file.
none

Open in new window

0
Comment
Question by:Sdurrani
  • 7
  • 3
  • 3
15 Comments
 

Author Comment

by:Sdurrani
ID: 24332856

import java.util.Random;

import java.lang.Thread;

import java.io.*;

import java.util.Scanner;

 

public class FinalExam {

 

      private int lineCount = 0;

      Random generator = new Random();

 

 

 

      int findNumberOfLines(String fileName) {

            FileReader reader;

            FileWriter writer;

            Scanner in = null;

            try {

 

                  reader = new FileReader("");

                  in = new Scanner(reader);

                  String line = null;

 

                  while (null != (line = in.nextLine())) {

 

                        lineCount++;

                  }

            }

 

            catch (Exception e) {

 

                  System.out.print("File cannot be found ");

                  System.exit(0);

            } finally {

                  in.close();

            }

 

            return lineCount;

      }

 

      public static void main(String[] args) {

            Numbers cl = new Numbers();

            Scanner console = new Scanner(System.in);

            System.out.println("Please enter the file name: ");

            String inputFileName = console.next();

 

              for (int i = 0; i < 100; i++) {

                                          int random = generator.nextInt(100) + 1;

                                          System.out.println(random);

                                    }

 

                         private void execute() {

                                testSort(generateArray(10000), RUN_TENK);

                                testSort(generateArray(100000), RUN_HUNDREDK);

                                testSort(generateArray(1000000), RUN_THOUSANDK);

                                printReport();

    }

            System.out.println("The number of lines in file " + inputFileName

                        + " is " + cl.findNumberOfLines(inputFileName) + "!");

      }

}

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24333718
>>The TreeSet method was what i was using for this so that it would be easier to sort.

Sorting is not a problem. You just need to generate n numbers and write them linewise using a PrintWriter to a file. Read them back into a List<Integer> using a Scanner and write them out to the output file. There's no need for counting file lines.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24333730
>>and write them out to the output file.

(after sorting them with Collections.sort(yourIntList) )
0
 
LVL 92

Expert Comment

by:objects
ID: 24333733
dupe q, either delete or reduce the points pls

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24333770
>>and write them out to the output file.

(after sorting them with Collections.sort(yourIntList) )
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24333774
>>dupe q,

A duplicate of what?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 86

Expert Comment

by:CEHJ
ID: 24333907
>>or reduce the points pls

btw Sdurrani, this should be pretty obvious, but you should never change the points level at the prompting of another expert unless that expert happens to be an employee of EE who has been authorised to make such a recommendation
0
 
LVL 92

Expert Comment

by:objects
ID: 24333921
0
 

Author Comment

by:Sdurrani
ID: 24335749
Hi there
I did not reduce the point level or increase the pts unless it was done by an EE employee
sorry
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 24335785
Sdurrani, don't worry. In case you didn't understand, what i'm saying is of course that you must ignore comments from other experts asking you to raise or lower points.
0
 

Author Comment

by:Sdurrani
ID: 24335831
oh ok .. thanks for clearing that up .. i just realized that i was going to write another question here while i was working on this current question however instead i reposted the same questions.. does that maek sense

ok so here is the acutal question

You are a technology coordinator at a school in the Upper East Side. The school
principal has asked you to create a simple program to keep track of student attending after school
activities. He would like you to do the following.
1. Using the Java Swing library to create an application that will be run at each event.
2. The application should at minimum ask the user for their first and last names, allow the user
to submit the data, and then goes on to accept another user.
3. The tool must be object-oriented, and must be comprised of at least 3 classes, of which
one must be abstract.
4. The students that are attending the event should be stored in some data structure such as
an Array, or any structure you believe best suits this software application. (You may use the
Java Collections framework).
5. There must be a button or some other output mechanism that allows the user to save
their output to an XML file out.xml that they can later rename and save. Once the
output is saved the program should end. To save the output as XML use Serialization.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24336028
>>Next time PLEASE do not try to explain ...

I won't. I'll call someone who does have the responsibility of giving direction on raising and lowering points

>>That is what objects said above

I'm not sure about that. If it's the question he says it is (
http://www.experts-exchange.com/Programming/Languages/Java/New_to_Java/Q_24380064.html ), then he's aware that the other question is already 500 points
0
 
LVL 92

Expert Comment

by:objects
ID: 24340732
> both will need to become 250 points :)

thanks :)

0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now