Java Program

User Generated

nnytun2

Programming

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().


User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer


Anonymous
I use Studypool every time I need help studying, and it never disappoints.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Related Tags