Problem 1 (1.5 points)



Similar documents
Problem 1 (2.5 points)

DIPLOMADO DE JAVA - OCA

Algorithms and Data Structures Written Exam Proposed SOLUTION

Resumen de Entrevista: Asociación de Agentes de Aduana del Puerto de Manzanillo

Bucle for_in. Sintaxis: Bucles for_in con listas. def assessment(grade_list): """ Computes the average of a list of grades

CmpSci 187: Programming with Data Structures Spring 2015

Sales Management Main Features

AV-002: Professional Web Component Development with Java

Cambridge IGCSE.

Exemplar for Internal Achievement Standard. Spanish Level 1

Apéndice C: Código Fuente del Programa DBConnection.java

ENVIRONMENT: Collaborative Learning Environment

COMPUTACIÓN ORIENTADA A SERVICIOS (PRÁCTICA) Dr. Mauricio Arroqui EXA-UNICEN

Customer Name Address City, State Zip <INSERT DATE>

AP Computer Science Java Subset

AP SPANISH LANGUAGE 2011 PRESENTATIONAL WRITING SCORING GUIDELINES

Verbos modales. In this class we look at modal verbs, which can be a tricky feature of English grammar.

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

Control of a variety of structures and idioms; occasional errors may occur, but

CS 111 Classes I 1. Software Organization View to this point:

OFFICE OF COMMON INTEREST COMMUNITY OMBUDSMAN CIC#: DEPARTMENT OF JUSTICE

Master English. Comparatives and Superlatives. Learn how to use comparatives and superlatives correctly. Download this handbook to your mobile phone

Inheritance, overloading and overriding

What is the Common Problem that Makes most Biological Databases Hard to Work With, if not Useless to most Biologists?

Schema XML_PGE.xsd. element GrupoInformes. attribute XML_PGE.xsd unqualified qualified

7.1 Our Current Model

Propiedades del esquema del Documento XML de envío:

Preparando a futuros profesores para integrar tecnología

Graduate Assessment Test (Sample)

LBWN ALQUILAR CON OPCIÓN A COMPRAR

SPAN 2113 Intermediate Spanish Schedule

Copyright TeachMe.com 242ea 1

J a v a Quiz (Unit 3, Test 0 Practice)

0530 SPANISH (FOREIGN LANGUAGE)

January 5, Writing assignments: 40% Final written report: 40% Oral exam: 20%

AP SPANISH LITERATURE 2009 SCORING GUIDELINES

learning science through inquiry in primary classroom Overview of workshop

Spanish GCSE Student Guide

Memorial Health Care System Catholic Health Initiatives Financial Assistance Application Form

Comments on Draft OECD/IOPS Good Practices on Pension Fund s Use of Alternative Investments and Derivatives

LINIO COLOMBIA. Starting-Up & Leading E-Commerce. Luca Ranaldi, CEO. Pedro Freire, VP Marketing and Business Development

Author: Sascha Wolski Sebastian Hennebrueder Tutorials for Struts, EJB, xdoclet and eclipse.

SUMMER WORK AP SPANISH LANGUAGE & CULTURE Bienvenidos a la clase de Español AP!

Instituto Cervantes - London

A. Before you read the text, answer the following question: What should a family do before starting to look for a new home?

Sub OPT() j = 1 k = 1 m = 1 n = 1 o = 1 g = 1 h = 1

Visión general de la integración con asanetwork

Java Interview Questions and Answers

Entry to Year 7 - Information for Parents

PROCEDIMIENTOPARALAGENERACIÓNDEMODELOS3DPARAMÉTRICOSA PARTIRDEMALLASOBTENIDASPORRELEVAMIENTOCONLÁSERESCÁNER

LOS ANGELES UNIFIED SCHOOL DISTRICT REFERENCE GUIDE

Global Art: A Sense of Caring Nos Preocupamos por los Demas

Manejo Basico del Servidor de Aplicaciones WebSphere Application Server 6.0

New words to remember

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

C:\Documents and Settings\Gijs\Desktop\src\client\Client.java dinsdag 3 november :50

Modificación de los Gastos operativos y de administración en JPMorgan Investment Funds y JPMorgan Funds

LOS ANGELES UNIFIED SCHOOL DISTRICT REFERENCE GUIDE

Física Computacional Conceptos de programación.

Object-Oriented Programming in C# (VS 2010)

Copyright TeachMe.com 4ea67 1

CompSci-61B, Data Structures Final Exam

Software Development with UML and Java 2 SDJ I2, Spring 2010

Application for Admission School Year

Curso OBJECT-ORIENTED PROGRAMMING IN VISUAL BASIC. (Visual Studio 2008)

3 Pillars of Object-oriented Programming. Industrial Programming Systems Programming & Scripting. Extending the Example.

Project AGUA Survey Results

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

Ask your child what he or she is learning to say in Spanish at school. Encourage your child to act as if he or she is your teacher.

DOCUMENT RESUME ED FL AUTHOR EDRS PRICE DESCRIPTORS

BtoB MKT Trends. El Escenario Online. Luciana Sario. Gerente de Marketing IDC Latin America 2009 IDC W W W. I D C. C O M / G M S 1

BANESTO FINANCIAL PRODUCTS PLC

API for java.util.iterator. ! hasnext() Are there more items in the list? ! next() Return the next item in the list.

QUOTE OF THE WEEK. KIDS ENABLED Resource Fair Our next All Pro Dad s meeting will be on February 5 th at 8am.

INFORMATIONAL NOTICE

Eugenia Vomvoridi-Ivanović University of South Florida

SPAN 100, Sections 7, 8, and 10 PLAN DEL CURSO PRIMAVERA 2012

An Incomplete C++ Primer. University of Wyoming MA 5310

Habanero Extreme Scale Software Research Project

Application for Admission School Year

Chapter 12 Intellectual Development from One One to Three to Three

LOS ANGELES UNIFIED SCHOOL DISTRICT REFERENCE GUIDE

Dictionary (catálogo)

CSE 308. Coding Conventions. Reference

Estructura de aplicación en PHP para System i

Unit 2. This is my job

This lecture. Abstract data types Stacks Queues. ADTs, Stacks, Queues Goodrich, Tamassia

General Certificate of Education Advanced Level Examination June 2014

SUMMER PROGRAM APPLICATION

Java Application Developer Certificate Program Competencies

Java CPD (I) Frans Coenen Department of Computer Science

Voices of Recent Latina Immigrants and Refugees:Effects of Budget Cuts on Their Settlement Experiences

Fecha: 04/12/2010. New standard treatment for breast cancer at early stages established

Transcription:

Leganés, June 17th, 2014 Time: 120 min Systems Programming Extraordinary Call (Problems) Grade: 5 points out of 10 from the exam Problem 1 (1.5 points) City councils apply two types of municipal taxes to buildings. The first one is the IBI (Building Property Tax, in Spanish Impuesto de Bienes Inmuebles ) and the second one is the TRU (Urban Garbage Tax, in Spanish Tasa de Residuos Urbanos ). The city council of our city defines the following interface for calculating these taxes. The IBI tax amount will be calculated by multiplying the area of the building (in square meters) by the BASIC IBI constant. public interface CityCouncilTaxes { static final double BASIC_IBI = 10.0; static final double FACADE_SUPPLEMENT = 20.0; static final double ROOM_SUPPLEMENT = 15.0; double calculateibi (); double calculatetru (); Section 1 (0.3 points) Write the code for the Estate class, which represents every element to which the taxes must be applied (basically, housing and establishments). This class must implement the CityCouncilTaxes interface. Take into account the following requirements: Estate class must have the following attributes. Notice that all attributes are private, except for age, which is protected so that it can be directly accessed from the subclasses without a get method. private String name; protected int age; private double area; // Estate s name // Number of years since the estate was built // Area in square meters The only constructor of the Estate class receives these three data as arguments. The class must implement the calculateibi() method. This method calculates the basic IBI, multiplying the estate area by the BASIC IBI constant defined by the city council. The calculatetru() method must not be implemented in the Estate class because there is not enough information to do it. Therefore, the children classes must be the ones implementing it. Remember that you have to indicate so in the class definition. Section 2 (0.7 points) Write the code for the Housing and Establishment classes, both of them extending the Estate class. Take into account that: Duplicate code or attributes will be penalized. The attributes must be private, except indicated otherwise. The Housing class must inherit the Estate class attributes, and have an additional attribute, called rooms. This attribute is an integer representing the number of rooms in the house.

The Establishment class must inherit the attributes of the Estate class, and have an additional attribute, called facadelength. This attribute is a real number representing the number of meters the establishment occupies in the street (i.e., the length of its facade). The constructor of the Housing class must receive the name, age, area and number of rooms. The constructor of the Establishment class must receive the name, age, area and length of the facade in meters. Both classes must override the calculateibi() method defined in the previous section. In order to implement it, you must use the method in the parent class (do not duplicate its code). The calculateibi() method in the Housing class must add to the IBI returned by the parent class a 20 % increment when the building age is less than 10 years. The calculateibi() method in the Establishment class must add an additional 10 % to the IBI returned by the method in the parent class when the establishment age is less than 20 years. Both classes must implement the calculatetru() method, but in a different manner. In the Housing class, the method must return the result of multiplying the ROOM SUPPLEMENT constant by the number of rooms in the house. The method in the Establishment class must return the result of multiplying the FACADE SUPPLEMENT by the length of the establishment facade (in meters). Section 3 (0.5 points) Write the code for the static void printaverageibimaxtru(estate data[]) method. This method must calculate the average value of the IBI, and the maximum value of the TRU, of the estates stored in the array received as argument, and then print these values to the standard output.

Problem 2 (3.5 points) An -ary tree is a tree that might have among 0 and infinite subtrees. It can be defined through mutual recursion in the following way: An -ary tree contains a datum and a forest. A forest is a queue of -ary trees. The following classes define a -ary tree that uses Strings as data. public class Tree { private String name; private Forest forest; public Tree(String name, Forest forest) { setname(name); setforest(forest); private void setname(string name) { if (name == null) { throw new IllegalArgumentException(); this.name = name; private void setforest(forest forest) { if (forest == null) { throw new IllegalArgumentException(); this.forest = forest; public class Forest implements Queue<Tree> { private Node<Tree> top; private Node<Tree> tail; private int size; public Forest() { top = null; tail = null; size = 0; public boolean isempty() { return (top == null); public int size() { return size; public Tree dequeue() { // assume this method is already coded public interface Queue<E> { boolean isempty(); int size(); void enqueue(e info); E dequeue(); class Node<E> { private E info; private Node<E> next; public Node(E info, Node<E> next) { setinfo(info); setnext(next); public Node<E> getnext() { return next; public E getinfo() { return info; public void setnext(node<e> next) { // assume this method is already coded public void setinfo(e info) { // assume this method is already coded // thrwos an exception if info is null Note: we recommend to solve the following sections in the same order they appear. Note: when solving the following sections, you CANNOT implement nor use any other additional classes or methods than the ones you are asked to implement in each section. Although, you can use the classes and methods mentioned in the initial description of the problem and the ones in the previous sections to the section your are solving.

Section 1 (0.75 points) Write the code for the public void enqueue(tree tree) method of the Forest class. If the implementation of this method is not efficient in time, the solution will be penalized with 0.3 points. Section 2 (0.5 points) Write the code for the public boolean isleaf() method in the Tree class. This method must return true if the tree with which the method is invoked is a leaf, or false otherwise. Section 3 (1 point) Write the code for the public static Tree Thor() method in a new Test class. This method must create, build and return the tree describing Durin s descendants, from Thór to Fíli and Kíli, as shown in the following figure: Thór Thráin II Frerin Thorin II Dís Fíli Kíli Section 4 (1.25 points) Implement the public String tostring() method in the Tree class. This method must return the textual representation of the tree data in pre-order, separated by end-of-line characters. In order to solve this section you also must implement the public String tostring() method of the Forest class. For instance, the result of printing the tree shown in the previous figure would be: Thór Thráin II Frerin Thorin II Dís Fíli Kíli Hint: in Java, you can obtain a String with the end-of-line characters by calling the System.lineSeparator() method.

Solution to section 1.1 (0.3 points) public abstract class Estate implements CityCouncilTaxes { private String name; protected int age; private double area; public Estate (String name, int age, double area){ this.name = name; this.age = age; this.area = area; public double calculateibi(){ return (area * BASIC_IBI); public abstract double calculatetru(); Solution to section 1.2 (0.7 points) public class Housing extends Estate { private int rooms; public Housing (String name, int age, double area, int rooms){ super(name, age, area); this.rooms = rooms; public double calculateibi() { if(super.age < 10) { return super.calculateibi() * 1.20; else { return super.calculateibi(); public double calculatetru() { return (ROOM_SUPPLEMENT * rooms); public class Establishment extends Estate {

private double facadelength; public Establishment (String name, int age, double area, double facadelength) { super(name, age, area); this.facadelength = facadelength; public double calculateibi() { if (super.age < 20) { return super.calculateibi() * 1.10; else { return super.calculateibi(); public double calculatetru() { return (FACADE_SUPPLEMENT * facadelength); Solution to section 1.3 (0.5 points) public static void printaverageibimaxtru(estate data[]) { double sumibi = 0.0; double maxtru = 0.0; for (int i=0; i<data.length; i++) { sumibi += data[i].calculateibi(); if (data[i].calculatetru() > maxtru) { maxtru = data[i].calculatetru(); System.out.println("Average IBI" + (sumibi / data.length)); System.out.println("Maximum TRU" + maxtru);

Solution to section 2.1 (0.75 points) public void enqueue(tree tree) { Node<Tree> n = new Node<Tree>(tree, null); if (isempty()) { top = n; else { tail.setnext(n); tail = n; size++; * 0,15 si tienen bien los generics * 0,15 si tienen bien el caso en que la cola está vacía * 0,30 si tienen bien el caso en la cola no está vacía (ignorando si es eficiente o no). * 0,15 si incrementan el tama~no * (-0.15) si tienen mal la signatura del método (por ejemplo, si usan E en vez de Tree) * (-0.30) si tienen mal la construcción del nodo * (-0,30) si recorren la cola para insertar Solution to section 2.2 (0.5 points) public boolean isleaf() { return forest.isempty(); * 0,5 si está bien, 0 en caso contrario.

Solution to section 2.3 (1 point) Thór Thráin II Frerin Thorin II Dís Fíli Kíli public class Test { public static Tree Thor() { // Fíli and Kíli Tree fili = new Tree("Fíli", new Forest()); Tree kili = new Tree("Kíli", new Forest()); // Dís Forest forest_dis = new Forest(); forest_dis.enqueue(fili); forest_dis.enqueue(kili); Tree dis = new Tree("Dís", forest_dis); // Frerin and Thorin II Tree frerin = new Tree("Frerin", new Forest()); Tree thorin2 = new Tree("Thorin II", new Forest()); // Thráin II Forest forest_thrain2 = new Forest(); forest_thrain2.enqueue(frerin); forest_thrain2.enqueue(thorin2); forest_thrain2.enqueue(dis); Tree thrain2 = new Tree("Thráin II", forest_thrain2); // Thór Forest forest_thor = new Forest(); forest_thor.enqueue(thrain2); Tree thor = new Tree("Thór", forest_thor); return thor; No importa si no declaran la clase Test. * 0,25 si usan correctamente el constructor de Tree * 0,25 si usan correctamente el constructor de Forest * 0,25 si encolan correctamente los árboles en los bosques # Estos 0,25 se reducen a 0,10 si el órden es el inverso * 0,25 si el árbol que construyen es correcto (las relaciones entre padres e hijos son correctas) * (-0,25) si no retornan el árbol una vez construido * Si usan nulls, como mucho tendrán un 0,25 si todo lo demás está bien.

Solution to section 2.4 (1.25 points) // Tree.java public String tostring() { if (isleaf()) { return name + System.lineSeparator(); else { return name + System.lineSeparator() + forest.tostring(); // Forest.java public String tostring() { String retval = new String(); for (Node<Tree> current = top; current!= null; current = current.getnext()) { retval += current.getinfo().tostring(); return retval; * 0,50 si se nota que entienden el concepto de recursión mútua, aunque tengan otras partes del apartado mal. * 0,15 si Tree.toString() es correcta en el caso base (ignorando el uso de EOL) * 0,15 si Tree.toString() es correcta en el caso recursivo (ignorando el uso de EOL) * 0,30 si Forest.toString() es correcta, independientemente si lo resuelven mediante recursión o iteración. # Estos 0,30 se reducen a 0,10 si se dejan el último nodo por recorrer * 0,15 si utilizan y emplazan correctamente el fin de línea. No importa si Tree.toString() está resuleto de forma iterativa usando la cola del enunciado. En ese caso se puntuará con 0,30 si la implementación es correcta (que es justo la suma del caso base y el recursivo si se hace por recursión). No importa si usan un String o un StringBuffer.