Solutions for Assignment 5 | Introduction to Computing - Java | CSC 116, Assignments of Java Programming

Material Type: Assignment; Class: Introduction to Computing - Java; Subject: Computer Science; University: North Carolina State University; Term: Spring 2005;

Typology: Assignments

Pre 2010

Uploaded on 03/11/2009

koofers-user-bj9
koofers-user-bj9 ๐Ÿ‡บ๐Ÿ‡ธ

5

(1)

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
๎˜๎˜‚๎˜๎˜ƒ๎˜„๎˜„๎˜…๎˜ƒ๎˜†๎˜ƒ๎˜‡๎˜‡๎˜ˆ๎˜ƒ๎˜‰๎˜Š๎˜‹๎˜Œ๎˜๎˜Ž๎˜๎˜๎˜ƒ๎˜๎˜‘๎˜’๎˜“๎˜Œ๎˜”๎˜๎˜’๎˜ƒ๎˜•๎˜–๎˜ƒ
๎˜ƒ
๎˜—๎˜Ž๎˜˜๎˜’๎˜™๎˜ƒ๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜‚๎˜›๎˜๎˜œ๎˜๎˜”๎˜›๎˜Š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜ƒ๎˜ƒ๎˜ž๎˜Š๎˜”๎˜๎˜Ÿ๎˜ƒ๎˜‰ ๎˜™๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜ƒ!๎˜Ž"๎˜™๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜ƒ
๎˜ƒ
#$๎˜’๎˜ƒ๎˜Œ๎˜›%๎˜’๎˜ƒ&๎˜“๎˜›'๎˜”%๎˜’%๎˜ƒ"๎˜’๎˜๎˜›(๎˜ƒ๎˜”๎˜๎˜ƒ๎˜Ž๎˜ƒ(๎˜›๎˜“)๎˜”๎˜Š*๎˜ƒ&๎˜”๎˜’๎˜Œ๎˜’๎˜ƒ๎˜›+๎˜ƒ๎˜Œ๎˜›%๎˜’๎˜ƒ๎˜๎˜›๎˜ƒ๎˜“๎˜’๎˜Ž%๎˜ƒ๎˜Ž๎˜ƒ๎˜Š๎˜œ๎˜˜"๎˜’๎˜“๎˜ƒ+๎˜“๎˜›๎˜˜๎˜ƒ๎˜’๎˜Ž๎˜Œ$๎˜ƒ๎˜๎˜”๎˜Š๎˜’๎˜ƒ๎˜”๎˜Š๎˜ƒ
๎˜Ž๎˜ƒ+๎˜”๎˜๎˜’๎˜ƒ๎˜Ž๎˜Š%๎˜ƒ๎˜๎˜œ๎˜˜๎˜ƒ๎˜$๎˜’๎˜ƒ๎˜Š๎˜œ๎˜˜"๎˜’๎˜“๎˜๎˜ƒ๎˜๎˜›*๎˜’๎˜$๎˜’๎˜“,๎˜ƒ๎˜ƒ-๎˜“๎˜”๎˜๎˜’๎˜ƒ๎˜$๎˜’๎˜ƒ๎˜Œ๎˜Ž๎˜๎˜Œ$๎˜ƒ&๎˜›๎˜“๎˜๎˜”๎˜›๎˜Š๎˜๎˜ƒ๎˜›+๎˜ƒ๎˜Œ๎˜›%๎˜’๎˜ƒ+๎˜›๎˜“๎˜ƒ๎˜$๎˜’๎˜ƒ+๎˜›๎˜๎˜๎˜›(๎˜”๎˜Š*๎˜ƒ
๎˜Œ๎˜›%๎˜’๎˜ƒ๎˜๎˜Š๎˜”&&๎˜’๎˜,๎˜ƒ๎˜ƒ๎˜‰+๎˜ƒ๎˜$๎˜’๎˜“๎˜’๎˜ƒ๎˜”๎˜๎˜ƒ๎˜Ž๎˜ƒ๎˜๎˜‚๎˜ƒ๎˜„๎˜…๎˜†๎˜‡๎˜ˆ๎˜†๎˜ƒ๎˜‰๎˜Š๎˜‹๎˜Œ๎˜๎˜…๎˜Ž๎˜Š๎˜๎˜ˆ๎˜๎˜ƒ&๎˜๎˜’๎˜Ž๎˜๎˜’๎˜ƒ&๎˜“๎˜”๎˜Š๎˜๎˜ƒ./๎˜Ž%๎˜ƒ๎˜Š๎˜œ๎˜˜"๎˜’๎˜“๎˜ƒ๎˜”๎˜Š๎˜ƒ+๎˜”๎˜๎˜’0,๎˜ƒ๎˜ƒ
๎˜‰+๎˜ƒ๎˜$๎˜’๎˜“๎˜’๎˜ƒ๎˜”๎˜๎˜ƒ๎˜Ž๎˜Š๎˜ƒ๎˜‘๎˜’๎˜‹๎˜Œ๎˜๎˜…๎˜Ž๎˜Š๎˜๎˜ˆ๎˜๎˜ƒ&๎˜๎˜’๎˜Ž๎˜๎˜’๎˜ƒ&๎˜“๎˜”๎˜Š๎˜๎˜ƒ.๎˜ž๎˜Š๎˜Ž"๎˜๎˜’๎˜ƒ๎˜๎˜›๎˜ƒ๎˜“๎˜’๎˜Ž%๎˜ƒ+๎˜”๎˜๎˜’0,๎˜ƒ๎˜ƒ#$๎˜’๎˜๎˜’๎˜ƒ๎˜’๎˜‘๎˜Œ๎˜’&๎˜๎˜”๎˜›๎˜Š๎˜๎˜ƒ๎˜$๎˜›๎˜œ๎˜%๎˜ƒ
"๎˜’๎˜ƒ&๎˜“๎˜”๎˜Š๎˜๎˜’%๎˜ƒ๎˜๎˜›๎˜ƒ๎˜$๎˜’๎˜ƒ๎˜๎˜’๎˜“๎˜˜๎˜”๎˜Š๎˜Ž๎˜๎˜ƒ(๎˜”๎˜Š%๎˜›(,๎˜ƒ
๎˜ƒ
๎˜๎˜‚๎˜ƒ๎˜„๎˜…๎˜†๎˜‡๎˜ˆ๎˜‰๎˜Š๎˜‰๎˜‹๎˜๎˜„๎˜‹๎˜Œ๎˜๎˜‡
๎˜‡
๎˜ƒ๎˜Ž๎˜๎˜๎˜๎˜‘๎˜‡๎˜‘๎˜๎˜‰๎˜’๎˜’๎˜‡๎˜“๎˜”๎˜’๎˜†๎˜•๎˜”๎˜‰๎˜–๎˜‡๎˜—๎˜‡
๎˜‡๎˜‡๎˜ƒ๎˜Ž๎˜๎˜๎˜๎˜‘๎˜‡๎˜’๎˜†๎˜‰๎˜†๎˜๎˜‘๎˜‡๎˜Š๎˜„๎˜๎˜–๎˜‡๎˜‚๎˜‰๎˜๎˜˜๎˜™๎˜š๎˜†๎˜…๎˜๎˜˜๎˜›๎˜œ๎˜๎˜‡๎˜‰๎˜…๎˜›๎˜’๎˜ž๎˜‡๎˜—๎˜‡
๎˜‡๎˜‡๎˜‡๎˜‡๎˜Ÿ๎˜Ž ๎˜”๎˜…๎˜”๎˜–๎˜•๎˜”๎˜‰๎˜–๎˜”๎˜…๎˜‡๎˜๎˜˜!๎˜˜๎˜Ž๎˜๎˜๎˜๎˜‡
๎˜‡๎˜‡๎˜‡๎˜‡๎˜†๎˜…"๎˜‡๎˜—๎˜‡
๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜๎˜˜๎˜†๎˜‡๎˜’๎˜Ž๎˜‚!#๎˜๎˜‡
๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜๎˜˜!๎˜˜๎˜”$๎˜‡๎˜Ÿ๎˜Ž ๎˜”๎˜…๎˜”๎˜–๎˜•๎˜”๎˜‰๎˜–๎˜”๎˜…๎˜™๎˜˜๎˜”$๎˜‡%๎˜๎˜๎˜”๎˜•๎˜”๎˜‰๎˜–๎˜”๎˜…๎˜™&๎˜๎˜˜๎˜ƒ๎˜Ž๎˜†&๎˜ž๎˜ž๎˜๎˜‡
๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜š๎˜†๎˜…๎˜๎˜˜๎˜›๎˜‡๎˜‚"'๎˜๎˜˜๎˜”!๎˜˜๎˜Ž๎˜๎˜๎˜๎˜‡
๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜–๎˜„๎˜‡๎˜—๎˜‡
๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜‚"'๎˜๎˜˜๎˜”!๎˜๎˜˜๎˜‹๎˜…๎˜”๎˜‰๎˜–'๎˜๎˜˜๎˜”๎˜™๎˜ž๎˜๎˜‡
๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜ ๎˜‡๎˜™๎˜‚"'๎˜๎˜˜๎˜”(!๎˜˜๎˜Ž๎˜๎˜๎˜ž๎˜‡
๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜’๎˜Ž๎˜‚)!*๎˜˜๎˜†๎˜”๎˜›๎˜”๎˜…๎˜‹๎˜ƒ๎˜‰๎˜…๎˜’๎˜”*๎˜˜๎˜†๎˜™๎˜‚"'๎˜๎˜˜๎˜”๎˜ž๎˜๎˜‡
๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡+๎˜‡$,๎˜๎˜๎˜”๎˜‡๎˜™๎˜‚"'๎˜๎˜˜๎˜”(!๎˜˜๎˜Ž๎˜๎˜๎˜ž๎˜๎˜‡
๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜๎˜˜๎˜‹๎˜‘๎˜๎˜„๎˜’๎˜”๎˜™๎˜ž๎˜๎˜‡
๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜š"๎˜’๎˜†๎˜”๎˜‚๎˜‹๎˜„๎˜Ž๎˜†๎˜‹๎˜ƒ๎˜…๎˜๎˜˜๎˜†๎˜๎˜˜๎˜™&๎˜“,๎˜”๎˜‡๎˜’๎˜Ž๎˜‚๎˜‡๎˜„ ๎˜‡๎˜†,๎˜”๎˜‡๎˜˜๎˜Ž๎˜‚๎˜๎˜”๎˜…๎˜’๎˜‡๎˜๎˜’๎˜‡&)๎˜’๎˜Ž๎˜‚๎˜ž๎˜๎˜‡
๎˜‡๎˜‡๎˜‡๎˜‡+๎˜‡
๎˜‡
๎˜‡๎˜‡๎˜‡๎˜‡๎˜๎˜๎˜‚๎˜ƒ๎˜„๎˜…๎˜†๎˜‡๎˜…๎˜ˆ๎˜†๎˜‡๎˜‰๎˜Š๎˜…๎˜‰๎˜ˆ๎˜‡๎˜‹๎˜…๎˜Š๎˜…๎˜†๎˜Œ๎˜†๎˜๎˜…๎˜‹๎˜‡๎˜…๎˜ˆ๎˜Š๎˜…๎˜‡๎˜Ž๎˜๎˜‡๎˜ˆ๎˜†๎˜ƒ๎˜†๎˜‡๎˜๎˜๎˜‡๎˜๎˜๎˜‘๎˜ƒ๎˜‡๎˜’๎˜‘๎˜„๎˜“๎˜”๎˜‡๎˜‡
๎˜‡
๎˜‡๎˜‡๎˜‡๎˜‡๎˜‰๎˜Š๎˜…๎˜‰๎˜ˆ๎˜•๎˜–๎˜—๎˜˜๎˜™๎˜‰๎˜†๎˜š๎˜…๎˜„๎˜๎˜๎˜‡๎˜†๎˜›๎˜‡๎˜œ๎˜‡
๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜๎˜๎˜‹๎˜…๎˜†๎˜Œ๎˜ž๎˜๎˜‘๎˜…๎˜ž๎˜š๎˜ƒ๎˜„๎˜๎˜…๎˜Ÿ๎˜๎˜• !๎˜๎˜Š"๎˜Ÿ๎˜†๎˜‡๎˜…๎˜๎˜‡๎˜ƒ๎˜†๎˜Š#๎˜‡$๎˜„๎˜Ÿ๎˜†%๎˜›&๎˜‡
๎˜‡๎˜‡๎˜‡๎˜‡'๎˜‡
๎˜‡๎˜‡๎˜‡๎˜‡๎˜‰๎˜Š๎˜…๎˜‰๎˜ˆ๎˜•(๎˜‘๎˜Œ"๎˜†๎˜ƒ)๎˜๎˜ƒ๎˜Œ๎˜Š๎˜…๎˜˜๎˜™๎˜‰๎˜†๎˜š๎˜…๎˜„๎˜๎˜๎˜‡๎˜†๎˜›๎˜‡๎˜œ๎˜‡
๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜‡๎˜๎˜๎˜‹๎˜…๎˜†๎˜Œ๎˜ž๎˜๎˜‘๎˜…๎˜ž๎˜š๎˜ƒ๎˜„๎˜๎˜…๎˜Ÿ๎˜๎˜• *๎˜Š#๎˜‡๎˜๎˜‘๎˜Œ"๎˜†๎˜ƒ๎˜‡๎˜„๎˜๎˜‡$๎˜„๎˜Ÿ๎˜†%๎˜›&๎˜‡
๎˜‡๎˜‡๎˜‡๎˜‡'๎˜‡
๎˜‡
๎˜‡
๎˜‡๎˜‡+๎˜‡
+๎˜‡

Partial preview of the text

Download Solutions for Assignment 5 | Introduction to Computing - Java | CSC 116 and more Assignments Java Programming in PDF only on Docsity!

CSC 116 โ€” 002 In-class Exercise #5 Name: Solution Unity ID: Lab: The code provided below is a working piece of code to read a number from each line in a file and sum the numbers together. Write the catch portions of code for the following code snippet. If there is a NumberFormatException please print โ€œBad number in fileโ€. If there is an IOException please print โ€œUnable to read fileโ€™. These exceptions should be printed to the terminal window. import java.io.*; public class TestRead { public static void main(String[] args) { BufferedReader in=null; try { int sum=0; in=new BufferedReader (new FileReader ("input") ); String myLine=null; do { myLine=in.readLine(); if (myLine!=null) sumt=Integer.parseInt (myLine) ; } while (myLine!=null); in.close(); System.out.println("The sum of the numbers is "+sum); } //Write the catch statements that go here on your quiz! catch(IOException e) { System.out.println(โ€œUnable to read fileโ€); } catch(NumberFormatException e) { System.out.println(โ€œBad number in fileโ€); }