Hello I am greatly in need of help with this java lab excerc

Hello. I am greatly in need of help with this java lab excercise. I am trying this but am getting frustrated. Can you PLEASE help!! Thank you so much!!

Loops Purpose The purpose of this lab is to introduce the File class, and the use of iteration based on boolean expressions. You will be using the Java while statement for this purpose. Objectives The objectives of this lab are: 1. Create a Scanner that reads input lines from a File object 2. Construct a while statement that reads the contents of a file, keeps a line count, then capitalizes each line Setup 1. Log in to your workstations as you did for the previous labs, then start the Netbeans application 2. Create a new project (Select File New Project from the menu bar) Highlight General and Java Application\' and press the \'Next\' button. 3. Look for the field called \"Create Main Class\" and change name to \'Main\'. Now, press the Finish button 4. You are now ready to begin writing your program

Solution

Main.java


import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {

   public static void main(String[] args) throws FileNotFoundException {
       File file = new File(\"myfile.txt\");
       Scanner scan = new Scanner(file);
       String line;
       int lineNum = 0;
       while(scan.hasNextLine()){
           line = scan.nextLine();
           lineNum++;
           System.out.println(lineNum+\" : \"+line.toUpperCase());
       }
       scan.close();
   }

}

Output:

1 : THIS IS LINE NUMBER ONE
2 : THIS IS LINE NUMBER TWO
3 : THIS IS LINE 3

myfile.txt

This is line number one
This is line number two
This is line 3

Hello. I am greatly in need of help with this java lab excercise. I am trying this but am getting frustrated. Can you PLEASE help!! Thank you so much!! Loops Pu

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site