Java Program

Oct 12th, 2013
Anonymous
Category:
Calculus
Price: $15 USD

Question description


Problem 5.1 (Read Example 10-1 on Page 615)

Write a program that read data from a file (InputData.txt attached in the same web fold) that stores students’ names followed by their test scores and outputs the following information. All data read from files should be stored in Vector objects. Note that in InputData.txt, the first column is student’s name and second column is the score.

  1. Class average score;
  2. Name of all students whose test scores are below the class average with an appropriate message;
  3. Highest test score and the names of all the students having the highest score;

615.jpeg  616.jpeg 617.jpeg   InputData.txt 

Problem 5.2 

Write a program that prompts the user to enter the length of feet and inches and outputs the equivalent length in centimeters. If user enters a negative number of non-digit number, throw and handle an appropriate exception and prompt the user to enter another set of numbers. (Hint: look at the example on Pages 92-93 for conversion and the example on Page 776 for fixing error and continue)

92.jpeg  93.jpeg  /  776.jpeg  777.jpeg 

Bonus Problem:

Define the exception class TornadoException. The class should have two constructors, including one default constructor. If the eception is thrown with the default constructor, the method getMessage shall return- “Tornado: Take cover immediately!” The other constructor has a single parameter, say m, of the int type. If the exception is thrown with this constructor, the method getMessage shall return: “Tornado: m miles away; and approaching!”

  • Write a Java program to test the class TornadoException specific in Step 1.

(Hint: Look at examples 12-12/12-13 in Chapter 12)

12.12-12.13.jpeg   12.13.jpeg 

----------------------------------------------------------------------------------------- hits for some problems:

Hint for Problem 5.1:

Create two vectors:

Vector<String> Students = new Vector<String>();

Vector<Integer> Scores = new Vector<Integer>();

Read the file and put Students’ name into Vector Students and scores into Vector Scores (use method addElement)Go through Vector Scores and compute average and max (using method ElementAt to get element in the vector; Note that method size() tells the number of elements in a vector)Go through Vector Scoresif the element is same as max (or smaller than average), records the index of that element;use the recorded index to access and print student’s name from Vector Students-------------------------

Hint for Problem 5.2

Reuse the example on Page 776 for FixError and continue and implement a method to getNumber(). In this method, if the number is mismatch, InputMismatchExeception will be triggered. If the number is negative, you need to add statement “throw new Exception(“Number cannot be negative”) to manually trigger the exception. As you can see, in method getNumber(), you need to include two catch blocks: InputMismatchException nd Exception.Reuse the example on Pages 92-93 for conversion as main(). Call getNumber() to get feet and inches in main().


Tutor Answer

(Top Tutor) Studypool Tutor
School: New York University

Studypool has helped 1,244,100 students

Review from student
Studypool Student
" Excellent job "
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1826 tutors are online

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors