BuildingProgramF08wFILES

BuildingProgramF08wFILES - Building a Program There are...

Info icon This preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Building a Program There are several ways to construct a program but the best way is in small sections.
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Plan what you want to do! We are going to create a program that will read from a file and average the numbers. We are going to use Scanner to read the file. Once the file’s numbers have been averaged, we will write the average to an output file.
Image of page 2
Create the skeleton program import java.util.*; import java.io.*; public class fileDemo { public static void main(String[] args) { } // end of main }
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Next decision We will be inputting into the program therefore we will need to handle all possible errors that can result from this activity. We have two choices: use the try catch syntax The disadvantage of this method is that if we create anything within the try catch it will be local use throw syntax The disadvantage of this method is that we have less control over our errors i.e., we cannot redirect the program execution if there is an error.
Image of page 4
throw We will throw the exception since will we need to create the file handlers within the
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern