Programming and Problem Solving with Java

(やまだぃちぅ) #1
7.6 Implementing a Derived Class | 351

{

public static voidmain(String[] args) throwsIOException
{
Phone firstPhone;
BusinessPhone secondPhone;
BusinessPhone thirdPhone;
BusinessPhone fourthPhone;
PrintWriter outFile;
outFile = new PrintWriter(new FileWriter("DrPhoneOut"));
outFile.println("Test results for class Business Phone");
firstPhone = new Phone(523, 3733344);
secondPhone = new BusinessPhone(713, 2233121, 1234);
thirdPhone = new BusinessPhone(523, 3733344, 1234);
fourthPhone = new BusinessPhone(713, 2233121, 1234);
outFile.println("knowAreaCode: "+ firstPhone.knowAreaCode());
outFile.println("knowDigits: "+ firstPhone.knowDigits());
outFile.println("asDigits: "+ firstPhone.asDigits());
outFile.println("asString: "+ firstPhone.asString());
outFile.println("knowAreaCode business: "+
secondPhone.knowAreaCode());
outFile.println("knowDigits business: "+ secondPhone.knowDigits());
outFile.println("asDigits business: "+ secondPhone.asDigits());
outFile.println("asString business: "+ secondPhone.asString());
if (secondPhone.equals(thirdPhone))
outFile.println("two business phones are equal");
else
outFile.println("two business phones are not equal");
if (firstPhone.equals(secondPhone))
outFile.println("a phone and a business phone are equal");
else
outFile.println("a phone and a business phone are not equal");
if (firstPhone.equals(thirdPhone))
outFile.println("a phone and a business phone are equal");
else
outFile.println("a phone and a business phone are not equal");
if ( secondPhone.equals(fourthPhone))
outFile.println("two business phones are equal");
else
outFile.println("two business phones are not equal");
outFile.close();
}
}

Free download pdf