Question

In: Computer Science

There are three distinct areas you need to research and focus on to get your final...

There are three distinct areas you need to research and focus on to get your final done properly:

  • Process command line arguments to get the names of input and output files from the user using Elipse

  • Read and write information from and into the disk files

  • Parse the data read from input file, store in a variable, process it and then print it

    on the screen and into the output file.
    Here are couple of exercises, which will help you in writing code for the above problems.

9.1 Write a class named Exercise5. Your main method’s header looks like this:

public static void main(String[] args)
where, args is the String array of command line arguments passed by JVM. Write a

method processCLArguments() like this:

public static void processCLArguments(String[] args) if the command args contains less than two strings, it displays the message like this:

      Usage: java Exercise5 inputFile outputFile

If the arguments contains input and output file names it displays the message like this:

Input will be read from: input_final.txt Output will be written into: output_final.txt

9. 2 Write another static method called processInputOutputFiles(), which takes a String array as arguments which has names of input and output files.

    public static void processInputOutputFiles(
                                           String[] args)

It reads the content of the input file whose name is in the first element of args String array with the scores for unknown number of students like the following. The format of the data is, name of a student, followed by comma-separated scores of quiz1, quiz2, quiz3, quiz4, midterm 1, midterm 2 and final for that student:

Thui Bhu, 100, 90, 80, 100, 89, 99, 88
Ariana B. Smith, 90, 90, 100, 100, 99, 100, 95

//more students data

Read each line (scores of a student) at a time, and

a) display the output on the screen like this:

Student #: 1 Thui Bhu, 100, 90, 80, 100, 89, 99, 88
Student #: 2 Ariana B. Smith, 90, 90, 100, 100, 99, 100, 95

b) and print the output on the disk file whose name is given in the second element of args String array. The disk output looks like this:

Student #1 is: "Thui Bhu" whose raw scores are: 100: 90: 80: 100: 89: 99: 88: Student #2 is: "Ariana B. Smith" whose raw scores are: 90: 90: 100: 100: 99: 100: 95:

9.3 Research on how to give the command line arguments in your class file using Eclipse.

When starting a Java application, you may want to supply few input parameters to your application even before your program starts. For example, giving database names, supplying username and password etc.

Supplying these arguments before the application starts differs in the way you start your application. You can run your Java application through command window (Windows) or terminal window (MAC). You can even supply these arguments while running from your favorite IDE, e.g. Eclipse.

So, there are two questions:

  1. a) How do you supply these arguments to your program, and

  2. b) How do you process these arguments in your program

Solutions

Expert Solution

Hi,

Please find the java code below:

///////////////////////////////

Java code:

package exercise;

//Exercise5 class
public class Exercise5 {
   //method processCLArguments()
   public static void processCLArguments(String[] args) {
       //two arguments check
       if (args.length < 2) {
           System.out.println("Usage: java Exercise5 inputFile outputFile");
           System.exit(1);
       }
       else {
           System.out.println("Input will be read from: "+ args[0] + " Output will be written into: " + args[1]);
           System.out.println();   }
   }


   public static void main(String[] args) {
       //invoke the method
       processCLArguments(args);
   }
}

Screenshot:

We can set the command line arguments in Eclipse IDE

using Run configuration.

Right click >> Run configuration

/////////////////////////////

Let me know if you need more help on this in the comments.
HOpe this helps.


Related Solutions

Hello, What other info do you need.   For your final project, choose three areas of healthcare...
Hello, What other info do you need.   For your final project, choose three areas of healthcare ethics that interest you. These could be topical areas or current events. In a single document, summarize each of the three areas in two paragraphs per case, and why you would like to explore them. Ask one ethical and one legal question that might be present within the realm of each topic. 1, Confidentiality - The protection of private patient information in the medical...
Managerial Decision Making Research and Analysis Focus of the Final Paper Research a specific company of...
Managerial Decision Making Research and Analysis Focus of the Final Paper Research a specific company of your choice and identify some of the managerial decisions that were made over time and in response to changes in its market or competitive environment. Use the Ashford University Library and web-based sources for your research. At least three external scholarly sources must be used in addition to the textbook. Address all of the following areas: Describe the company and provide a brief history...
Using your knowledge of pathophysiology and research, you will need to present a differential of three...
Using your knowledge of pathophysiology and research, you will need to present a differential of three disorders that could account for your patient’s symptoms. Patient 1: 35-year-old man with a history of anxiety, chronic marijuana use, and chronic back pain. No current medications or other history, but he has been consistently complaining of back pain since joining the Thursday night league volleyball team. Single, lives alone, and works at a fast food restaurant. Heterosexual and consistent use of protection (barrier)....
Historians divide Colonial America into three distinct regions. Compare and contrast these three different areas and...
Historians divide Colonial America into three distinct regions. Compare and contrast these three different areas and discuss why each region developed in a unique way?
as it relates to COVID-19 what areas need research
as it relates to COVID-19 what areas need research
Your friend usually gets a 76% on their tests and you get an 80%. If final...
Your friend usually gets a 76% on their tests and you get an 80%. If final test is worth 300 points, how often will your friend randomly get more points than you on the test ? Thats what I was asked to solve, no more info given. Please if you can do it, I have to submit it today
1.Historians divide Colonial America into three distinct regions. Compare and contrast these three different areas and...
1.Historians divide Colonial America into three distinct regions. Compare and contrast these three different areas and discuss why each region developed in a unique way. 2. Compare and contrast the society that developed in Colonial America with European society at this same time. What historical factors might explain the differences between the two societies? 3. indentured servant
Identify three (3) distinct areas of technology that are showing up in today’s nonprofit organizations. For...
Identify three (3) distinct areas of technology that are showing up in today’s nonprofit organizations. For each area, and then describe a specific example of how this technology is being used to be of practical help to the organization
Discussion Question: The Malcolm Baldrige website identified many areas that leaders need to focus on with...
Discussion Question: The Malcolm Baldrige website identified many areas that leaders need to focus on with respect to improving and succeeding with excellence in quality (for example: leadership, effectiveness, sustainability, innovation, world class, etc.). Identify the 2-3 areas that your present company focuses on and discuss the benefits from them. Also identify 2-3 areas where your company could further benefit if it focused more on those areas.
1. What are the three areas of focus in Community Nutrition? 2. What are the four...
1. What are the three areas of focus in Community Nutrition? 2. What are the four shared components of a community? 3. What is health disparities? 4. What is public health nutrition? 5. What is HP 2020? 6. What is the socioecological model? 7. What are the different types of studies and their advantages/disadvantages? 8. How is distribution vs. determinants? 9. What is considered vital statistics? 10. What are the behavior change theories? 11. What are the different ways to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT