Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Doublé speed * ;
Animal() {
weight = 50;
height = 4;
__Ejercicio # 2 _______________________
Weight = w;
Height = h;
Speed = s;
______________________________________
public double getTime(double miles){ //gets the number of hours to go these miles
return miles/speed;
return weight;
}
public int getHeight(){
return height;
return speed;
3.Ejercicio
-Escriba el código para crear dos instancias de la plantilla de clase Animal incluida en el
problema número 2. Asegúrese de utilizar ambos constructores proporcionados. Luego,
agregue un código Java que imprimirá lo siguiente: a. El animal 1 tiene una velocidad de ___. b.
El animal 2 tiene una velocidad de ___. Asegúrese de que los espacios en blanco se completen
automáticamente con las velocidades reales. Utilice los métodos proporcionados para acceder
a las velocidades.
4._Ejercicio
Escriba una clase Estudiante. Debe tener las siguientes variables de instancias para el nombre,
los créditos, el promedio ponderado (GPA) y los puntos de calidad. Cree un método
constructor. Cree los otros dos métodos de la siguiente manera: a. Un método que devolverá
el promedio ponderado actual, que serán los puntos de calidad divididos por los créditos. b. Un
método que tomará los créditos de la clase o el semestre junto con los puntos de calidad.
Debe actualizar los créditos, los puntos de calidad y el GPA.
String name;
int credits,qualityPoints;
double gpa;
this.credits = credits;
this.qualityPoints = qualityPoints;
gpa = (double)qualityPoints/(double)credits;
return gpa;
this.credits += credits;
this.qualityPoints += qualityPoints;
gpa = (double)qualityPoints/(double)credits;
Ejercicio # 1
Cree una forma de clase simple que representa una forma en 2 dimensiones con segmentos de
líneas para los bordes. Debe tener la siguiente variable instancia: numSides (int), regular
(booleano). Cree al menos dos constructores y métodos captadores y establecedores. public
class Shape {
Shape(){
numSides = 3; regular=true;
numSides = n;
this.regular = regular;
}
public boolean isRegular(){
return regular;
return numSides;
numSides = s;
this.regular = regular;
5.- Con la clase creada en el número 4, cree tres instancias de la clase Estudiante de la tabla a
continuación
ari.addCredits,5(132);
PROYECTO JF SECTION 7 7.2
package inventario;
import java.util.InputMismatchException;
import java.util.Scanner;
maxProduct = getNumProducts(Sca);
if(maxProduct ==0) {
}else {
Producto[] products = new Producto[maxProduct];
addToInventory(products, Sca);
do {
menuChoice = getMenuOption(Sca);
}while(menuChoice!=0);
}//endif
switch(choice) {
displayInventory(products);
break;
case 2: System.out.println("Agregar existencias");
addInventory(products, Sca);
break;
deductInventory(products, Sca);
break;
discontinueInventory(products, Sca);
break;
}//final de switch
int productChoice;
productChoice=getProductNumber(products, Sca);
products[productChoice].setActivo(false);
int productChoice;
productChoice=getProductNumber(products, Sca);
do {
try {
updateValue = Sca.nextInt();
if(updateValue <0)
}catch(InputMismatchException e) {
Sca.nextLine();
}catch(Exception e) {
System.out.println(e);
Sca.nextLine();
int productChoice;
int updateValue=-1;
productChoice=getProductNumber(products, Sca);
do {
try {
updateValue = Sca.nextInt();
if(updateValue <0)
//endif
}catch(InputMismatchException e) {
Sca.nextLine();
}catch(Exception e) {
System.out.println(e);
Sca.nextLine();
}while(updateValue <0);
products[productChoice].addToInventory(updateValue);
int productChoice=-1;
//endor
do {
try {
productChoice = Sca.nextInt();
+ (products.length-1));
//endif
}catch(InputMismatchException e) {
Sca.nextLine();
}catch(Exception e) {
System.out.println(e);
Sca.nextLine();
return productChoice;
int menuOption=-1;
do {
try {
menuOption = Sca.nextInt();
}catch(InputMismatchException e) {
Sca.nextLine();
}catch(Exception e) {
System.out.println(e);
Sca.nextLine();
return menuOption;
}//end method getMenuOption
int maxSize=-1;
do {
try{
maxSize = Sca.nextInt();
if(maxSize<0)
catch(InputMismatchException e) {
Sca.nextLine();
}catch(Exception e){
System.out.println(e);
Sca.nextLine();
}while(maxSize<0);
return maxSize;
int stockChoice=-1;
do {
try {
stockChoice = Sca.nextInt();
//endif
}catch(InputMismatchException e) {
System.out.println("Tipo de datos incorrecto introducido.");
Sca.nextLine();
}catch(Exception e) {
System.out.println(e);
Sca.nextLine();
if(stockChoice==1)
else
//endif
}//endfor
}//final del método addToInventory
int tempNumber;
String tempName;
int tempQty;
double tempPrice;
String tempArtist;
int tempNumSongs;
String tempLabel;
Sca.nextLine();
tempName = Sca.nextLine();
tempLabel = Sca.nextLine();
tempNumSongs = Sca.nextInt();
tempQty = Sca.nextInt();
tempPrice = Sca.nextDouble();
tempNumber = Sca.nextInt();
int tempNumber;
String tempName;
int tempQty;
double tempPrice;
int tempLength;
int tempRating;
String tempStudio;
Sca.nextLine();
tempName = Sca.nextLine();
tempStudio = Sca.nextLine();
tempRating = Sca.nextInt();
tempLength = Sca.nextInt();
tempQty = Sca.nextInt();
tempPrice = Sca.nextDouble();
tempRating, tempStudio);
System.out.println(product);
//endor