Helsingin yliopisto / Tietojenkäsittelytieteen
laitos / 581258-1 Johdatus ohjelmointiin
Copyright © 1997 Arto
Wikla. The use of this material is only allowed for studying purposes
of private persons. Any other use of this material, such as commercial
or other courses, is forbidden.
Please write on the top of each of your papers the name of the course, the date of the exam, your name, your date of birth and your signature.
You may use the tools of the Lue-class when writing your programs.
primitive type - reference type compilation unit - package instantiation (creating an object) - class loading (6 points)
(5 points)
public class Example { public int[] iT; static private double d; public Example() { iT = new int[10]; d = 3.14; } void metA() { System.out.println(iT.length); } public int metB(int par) { return iT.length+par; } static String metC(char c) { return ""+d+c; } }
Write a subclass Sub for the class Example. Sub must hide the field d, override the method metC, inherit the method metB and overload the method metA.What is the easiest way to use the hidden, overridden, inherited, and overloaded parts in class Sub? Or is it possible to use them?
(5 points)
(5 points)
InpFile(String name) that creates an InpFile object with which you can read a text file. The name of the file is passed as a parameter. If the file is not found, the read-method will return null values right from the start. So, empty and missing files will behave similarly to the user of this class! The user doesn't have to take care for any exceptions.
The class contains a method for reading lines:
By using this class, write a program that asks the user for the name of the input file, a character to be replaced (oldChar), and a replacing character (newChar). Then the program prints the file, modified so that all oldChar-characters are replaced by the newChar-character.
(5 points)