/* Valuation.java * * Translated by: Thomas Lauritsen * * Execise 26 (examination exercise 3 from ITU, January 2000): * Calculates tax assessments of real estates. */ /* Class RealEstate as given in the text */ class RealEstate { House house; Site site; RealEstate(House house, Site site) { this.house = house; this.site = site; } int valuation() { return house.valuation() + site.valuation(); } } /* Question 3.1: Class House */ class House { int area; int costPerSquareMeter; House(int area, int costPerSquareMeter) { this.area = area; this.costPerSquareMeter = costPerSquareMeter; } int valuation() { // Valuation of a house is the area times // the cost per area. return area * costPerSquareMeter; } } /* Question 3.2: Class Site */ class Site { int area; int costPerSquareMeter; int buildingPrivilege; Site(int area, int costPerSquareMeter, int buildingPrivilege) { this.area = area; this.costPerSquareMeter = costPerSquareMeter; this.buildingPrivilege = buildingPrivilege; } int valuation() { // Valuation of a site is area times cost per area // plus privilege. return area * costPerSquareMeter + buildingPrivilege; } } class Valuation { /* Question 3.3: valuation method */ static int valuation(RealEstate[] estates) { // loop through all realestates and sum // their valuation. int sum = 0; for (int i = 0; i < estates.length; i++) { sum = sum + estates[i].valuation(); } return sum; } /* main method as given in the text */ public static void main(String[] args) { RealEstate k29 = new RealEstate(new House(200, 8000), new Site(800, 500, 400000)); RealEstate a11 = new RealEstate(new House( 70, 4000), new Site(700, 30, 24000)); RealEstate[] estates = {k29, a11}; System.out.println(valuation(estates)); } } /* Question 3.4: class PollutedSite */ class PollutedSite extends Site { int reduction; PollutedSite(int area, int costPerSquareMeter, int buildingPrivilege, int reduction) { // call Site's constructor super(area, costPerSquareMeter, buildingPrivilege); this.reduction = reduction; } int valuation() { // Valutation of a polluted site is the valuation // of a similar unpolluted site minus a reduction. return super.valuation() - reduction; } void setReduction(int reduction) { this.reduction = reduction; } }