Java Reference
In-Depth Information
Write a program that outputs the number of characters, words, and
lines in the files that are supplied as command-line arguments.
2.31
In Java, floating-point divide-by-zero is legal and does not result in an
exception (instead, it gives a representation of infinity, negative infin-
ity, or a special not-a-number symbol).
a.
2.32
Verify the above description by performing some floating-point
divisions.
b.
Write a static divide method that takes two parameters and
returns their quotient. If the divisor is 0.0, throw an
ArithmeticException . Is a throws clause needed?
c.
Write a main program that calls divide and catches the
ArithmeticException . In which method should the catch clause be
placed?
Implement a text file copy program. Include a test to make sure that
the source and destination files are different.
2.33
Each line of a file contains a name (as a string) and an age (as an integer).
a.
2.34
Write a program that outputs the oldest person; in case of ties,
output any person.
b.
Write a program that outputs the oldest person; in case of ties,
output all oldest people ( Hint: Maintain the current group of old-
est people in an ArrayList .)
Write a program that calculates the grades for a course. Your program
should prompt the user for the name of a file that stores exam scores.
Each line of the file has the following format:
2.35
LastName:FirstName:Exam1:Exam2:Exam3
The exams are to be weighted 25% for the first exam, 30% for the second
exam, and 45% for the third exam. Based on that, a final grade is to be
assigned: A if the total is at least 90, B if it is at last 80, C if it is at least
70, D if it is at least 60, and F otherwise. The highest grade based on the
total points is always assigned, so a 75 gets a C.
Your program should output to the terminal a list of students with the let-
ter grade, as follows:
LastName FirstName LetterGrade
It should also output to a file, whose name is provided by the user, lines
of the form
LastName FirstName Exam1 Exam2 Exam3 TotalPoints LetterGrade
Search WWH ::




Custom Search