Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

Examen de poo

Rating
-
Sold
-
Pages
5
Grade
10 (Matrícula de Hon
Uploaded on
07-06-2025
Written in
2022/2023

Examen con respuesta de Herencia y Polimorfismo

Institution
Course

Content preview

Examen Unidad III Y IV
Escribir un programa en Lenguaje Java que resuelva el siguiente problema: En el
establo “Ok Corral” se cuidan caballos y cada caballo tiene un nombre, un color y
un año de nacimiento. Además, algunos caballos son caballos de carrera, de los
cuales se registran el número de carreras en las que ha participado. Basados en la
siguiente clase Caballo, se desea que se implemente la clase CaballoDeCarrera
(por medio de herencia) y un programa que pruebe ambas clases solicitando el
número de caballos en el establo, pidiendo sus datos (se debe preguntar si el
caballo es de carrera) y desplegando una relación de los caballos en pantalla.
Respuesta:
Clase caballo:
//Caballo.java

public class Caballo

{

private String nombre;

private String color;

private int nacimiento;

public Caballo( String nombre, String color, int nacimiento )

{

setNombre( nombre );

setColor( color );

setNacimiento( nacimiento );

}

public void setNombre( String nombre )

{

this.nombre = nombre;

}

public void setColor( String color )

{

this.color = color;

}

public void setNacimiento( int nacimiento )

{

, this.nacimiento = nacimiento;

}

public String getNombre()

{

return nombre;

}

public String getColor()

{

return color;

}

public int getNacimiento()

{

return nacimiento;

}

public String toString()

{

String resultado = String.format( "Nombre: %s Color: %s Año de Nacimiento: %d",
nombre, color, nacimiento );

return resultado;

}

}

Clase CaballodeCarrera heredada de Clase Caballo:
//CaballodeCarrera.java

public class CaballodeCarrera extends Caballo

{

//Atributos

private int numdeCarreras;

//Constructor

public CaballodeCarrera(int numdeCarreras, String nombre, String color, int nacimiento)

{

super(nombre, color, nacimiento);

setNumdeCarreras(numdeCarreras);

Written for

Institution
Course

Document information

Uploaded on
June 7, 2025
Number of pages
5
Written in
2022/2023
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$9.19
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
joseangelgarciaperez

Get to know the seller

Seller avatar
joseangelgarciaperez Instituto Tecnológico de Culiacan
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
11 months
Number of followers
0
Documents
1
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions