commit

parents
public class BoxHerencia {
public static void main(String[] args){
Envio envio1 = new Envio(15.2f);
Envio envio2 = new Envio(5f, 6f, 10f, 15f);
System.out.println("El envio uno tiene un volumen de : "+envio1.calcularVolumen()
+"\nEl envio dos tiene un volumen de: "+envio2.calcularVolumen());
}
}
class Caja{
private float ancho;
private float alto;
private float profundidad;
public Caja(Caja caja){
this.ancho = caja.getAncho();
this.alto = caja.getAlto();
this.profundidad = caja.getProfundidad();
}
public Caja(float ancho, float alto, float profundidad) {
this.ancho = ancho;
this.alto = alto;
this.profundidad = profundidad;
}
public Caja(){
super();
}
public Caja(float lado){
this.alto = lado;
this.ancho = lado;
this.profundidad = lado;
}
public float calcularVolumen(){
return this.alto*this.ancho*this.alto;
}
public float getAncho() {
return ancho;
}
public void setAncho(float ancho) {
this.ancho = ancho;
}
public float getAlto() {
return alto;
}
public void setAlto(float alto) {
this.alto = alto;
}
public float getProfundidad() {
return profundidad;
}
public void setProfundidad(float profundidad) {
this.profundidad = profundidad;
}
}
class CajaPeso extends Caja{
private float peso;
public CajaPeso(float ancho, float largo, float profundidad, float peso){
super(ancho, largo, profundidad);
this.peso = peso;
}
public CajaPeso(){
super();
}
public float getPeso() {
return peso;
}
public void setPeso(float peso) {
this.peso = peso;
}
}
class Envio extends CajaPeso{
public Envio(){
super();
}
public Envio(Envio envio){
super();
this.setAncho(envio.getAncho());
this.setAlto(envio.getAlto());
this.setProfundidad(envio.getProfundidad());
this.setPeso(envio.getPeso());
}
public Envio(float lado){
super();
this.setAncho(lado);
this.setProfundidad(lado);
this.setAlto(lado);
}
public Envio(float ancho, float largo, float profundidad, float peso){
super(ancho, largo, profundidad, peso);
}
}
\ No newline at end of file
public class Factura {
/*
* Testeo de metodos y variables static.
* */
private static float iva1;
private static float iva2;
int productos;
public static void setIva(float ivax, float ivay){
iva1 = ivax;
iva2 = ivay;
}
public static float getIva1(){
return iva1;
}
public static float getIva2(){
return iva2;
}
public static void testError(){
// productos = 0;
}
public static void main(String[] args){
Factura.setIva(5f, 10f);
System.out.println("Probando valores static, iva 1: "+Factura.getIva1()+" Iva2: "+Factura.getIva2());
}
}
import java.util.ArrayList;
import java.util.Scanner;
public class Mochila {
/*
* Clase que representa un mochila en la cual se podra cargar Objetos
* Atributos: maxPeso, valorTransportado, pesoOcupado, ObjetosDisponibles y ObjetosCargados
* Metodos Importantes :
* Constructor: Instancia una mochila y le asigna un peso maximo;
* cargarMochilaEficientemente: Carga la mochila con los objetos disponibles;
* fillMochila: Clase helper de cargarMochilaEficientemente que rellena el ArrayList con los objetos cargados.
* */
private int maxPeso;
private int valorTransportado = 0;
private int pesoOcupado = 0;
ArrayList<Objeto> objetosDisponibles;
ArrayList<Objeto> objetosCargados;
public Mochila(int maxPeso){
this.maxPeso = maxPeso;
this.objetosDisponibles = new ArrayList<Objeto>();
this.objetosCargados = new ArrayList<Objeto>();
}
public float getMaxPeso() {
return maxPeso;
}
public void setMaxPeso(int maxPeso) {
this.maxPeso = maxPeso;
}
public int getValorTransportado() {
return valorTransportado;
}
public void setValorTransportado(int valorTransportado) {
this.valorTransportado = valorTransportado;
}
public int getPesoOcupado() {
return pesoOcupado;
}
public void setPesoOcupado(int pesoOcupado) {
this.pesoOcupado = pesoOcupado;
}
public void cargarMochila(int value, int peso){
objetosDisponibles.add(new Objeto(value, peso));
}
public void imprimirObjDispobibles(){
for(Objeto obj: objetosDisponibles){
System.out.print("[val: "+obj.getValue()+", peso: "+obj.getPeso()+"]-");
}
System.out.println();
}
public void imprimirObjCargados(){
for(Objeto obj: objetosCargados){
System.out.print("[val: "+obj.getValue()+", peso: "+obj.getPeso()+"]-");
}
System.out.println();
}
private void fillMochila(String values){
for(int i=0;i<values.length();i++){
objetosCargados.add(objetosDisponibles.get((Character.getNumericValue(values.charAt(i)))));
pesoOcupado += objetosCargados.get(i).getPeso();
}
}
private static int max(int i, int j)
{
return (i > j) ? i : j;
}
private void cargarMochilaEficientemente()
{
objetosCargados.clear();
pesoOcupado = 0;
int[] dp = new int[maxPeso + 1];
String[] flags = new String[maxPeso + 1];
for(int i=0;i<maxPeso+1;i++){
flags[i] = "";
}
for(int i = 0; i <= maxPeso; i++){
String temp2="";
for(int j = 0; j < objetosDisponibles.size(); j++){
if(objetosDisponibles.get(j).getPeso() <= i){
int temp = dp[i];
dp[i] = max(dp[i], dp[i - objetosDisponibles.get(j).getPeso()] +
objetosDisponibles.get(j).getValue());
if(!(dp[i] == temp)){
temp2 = ""+flags[i - objetosDisponibles.get(j).getPeso()]+j;
}
}
}
flags[i] = temp2;
}
fillMochila(flags[maxPeso]);
valorTransportado = dp[maxPeso];
}
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.println("Ingrese la capacidad maxima de su mochila en KG: ");
int capacidad = in.nextInt();
Mochila mochila = new Mochila(capacidad);
int choice=0;
int valor = 0;
int peso = 0;
boolean continuar = true;
do{
System.out.println("Peso Maximo: "+capacidad+
"\nValor Transportado: "+mochila.getValorTransportado()+
"\nPeso Ocupado: "+mochila.getPesoOcupado()+
"\n-------------------\n1 - Crear Objeto\n2 - Imprimir Objetos Disponibles\n3 - Imprimir Objetos de Mochila\n4 - AutoRellenar Mochila\n5 - Salir\nEntrada: ");
try{
choice = in.nextInt();
}catch (Exception e){
System.out.println("Entrada no validad");
}
switch (choice){
case 1:
System.out.println("Ingrese el valor del objeto: ");
valor = in.nextInt();
System.out.println("Ingrese el peso del objeto: ");
peso = in.nextInt();
mochila.cargarMochila(valor, peso);
break;
case 2:
mochila.imprimirObjDispobibles();
break;
case 3:
mochila.imprimirObjCargados();
break;
case 4:
System.out.println("Mochila Cargada!");
mochila.cargarMochilaEficientemente();
break;
case 5:
System.out.println("Saliendo...");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
continuar = false;
break;
default:
System.out.println("Eleccion no validad");
}
}while(continuar);
}
}
class Objeto {
/*
* Clase que representa objetos que se pueden cargar en la mochila
* Atributos: peso y valor
* */
private int peso;
private int value;
public Objeto(int value, int peso){
this.value = value;
this.peso = peso;
}
public int getPeso() {
return peso;
}
public void setPeso(int peso) {
this.peso = peso;
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
}
class Client{
/*
* Clase padre de la cual heredaran las clases Premium, Oro y Plata
* */
private String nombre;
private String ruc;
private int numVisita;
private Producto[] productosCompradosNow;
private Servicio[] serviciosCompradosNow;
public String getRuc() {
return ruc;
}
public void setRuc(String ruc) {
this.ruc = ruc;
}
public Client(String nombre, String ruc, Producto[] productosCompradosNow, Servicio[] serviciosCompradosNow) {
this.nombre = nombre;
this.ruc = ruc;
this.productosCompradosNow = productosCompradosNow;
this.serviciosCompradosNow = serviciosCompradosNow;
this.numVisita = (int)(Math.random()*125);
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public int getNumVisita() {
return numVisita;
}
public void setNumVisita(int numVisita) {
this.numVisita = numVisita;
}
public void addVisita(){
numVisita++;
}
public Producto[] getProductosCompradosNow() {
return productosCompradosNow;
}
public Servicio[] getServiciosCompradosNow() {
return serviciosCompradosNow;
}
public void setProductosCompradosNow(Producto[] productosCompradosNow) {
this.productosCompradosNow = productosCompradosNow;
}
public void setServiciosCompradosNow(Servicio[] serviciosCompradosNow) {
this.serviciosCompradosNow = serviciosCompradosNow;
}
public float calcularTotalFactura(){
int descuento;
if(this instanceof PremiumClient){
descuento = 30;
}else if(this instanceof OroClient){
descuento = 20;
}else if(this instanceof PlataClient){
descuento = 10;
}else{
descuento = 0;
}
float montoTotal = 0;
for(Producto item: productosCompradosNow){
montoTotal += item.getPrecio();
}
for(Servicio item: serviciosCompradosNow){
montoTotal += item.getCosto();
}
return montoTotal - montoTotal*descuento/100;
}
}
class PremiumClient extends Client{
private String[] servicios;
private String[] beneficios;
private String[] premios;
public PremiumClient(String nombre, String ruc, Producto[] comprapro, Servicio[] compraserv, String[] servicios, String[] beneficios, String[] premios) {
super(nombre, ruc, comprapro, compraserv);
this.servicios =servicios;
this.beneficios = beneficios;
this.premios = premios;
}
public String[] getServicios() {
return servicios;
}
public void setServicios(String[] servicios) {
this.servicios = servicios;
}
public String[] getBeneficios() {
return beneficios;
}
public void setBeneficios(String[] beneficios) {
this.beneficios = beneficios;
}
public String[] getPremios() {
return premios;
}
public void setPremios(String[] premios) {
this.premios = premios;
}
}
class OroClient extends Client{
private String[] beneficios;
private String[] servicios;
public OroClient(String nombre, String ruc, Producto[] comprapro, Servicio[] compraserv, String[] servicios, String[] beneficios){
super(nombre, ruc, comprapro, compraserv);
this.beneficios = beneficios;
this.servicios = servicios;
}
public String[] getBeneficios() {
return beneficios;
}
public void setBeneficios(String[] beneficios) {
this.beneficios = beneficios;
}
public String[] getServicios() {
return servicios;
}
public void setServicios(String[] servicios) {
this.servicios = servicios;
}
}
class PlataClient extends Client{
private String[] servicios;
public PlataClient(String nombre, String ruc, Producto[] comprapro, Servicio[] compraserv, String[] servicios) {
super(nombre, ruc, comprapro, compraserv);
this.servicios = servicios;
}
public String[] getServicios() {
return servicios;
}
public void setServicios(String[] servicios) {
this.servicios = servicios;
}
}
class Producto{
private float precio;
private String descripcion;
public float getPrecio() {
return precio;
}
public void setPrecio(float precio) {
this.precio = precio;
}
public String getDescripcion() {
return descripcion;
}
public void setDescripcion(String descripcion) {
this.descripcion = descripcion;
}
public Producto(float precio, String descripcion) {
this.precio = precio;
this.descripcion = descripcion;
}
}
class Servicio{
private float costo;
private String descripcion;
public Servicio(float costo, String descripcion) {
this.costo = costo;
this.descripcion = descripcion;
}
public float getCosto() {
return costo;
}
public void setCosto(float costo) {
this.costo = costo;
}
public String getDescripcion() {
return descripcion;
}
public void setDescripcion(String descripcion) {
this.descripcion = descripcion;
}
}
public class SalonBellezaConHerencia {
public static void main(String[] args){
Producto producto1 = new Producto(15.4f, "Producto");
Servicio servicio1 = new Servicio(20.4f, "Servicio");
Producto[] productos = {producto1};
Servicio[] serviciosComprea = {servicio1};
Client client1 = new Client("Jose", "594", productos, serviciosComprea);
String[] servicios = {"pedicura", "manicura"};
String[] beneficios = {"Descuento 10%"};
String[] premios = {"Vale de compras", "Manicura de Regalo"};
PremiumClient client2 = new PremiumClient("Antonio", "564", productos, serviciosComprea, servicios, beneficios, premios);
OroClient client3 = new OroClient("Juan", "548", productos, serviciosComprea, servicios, beneficios);
PlataClient client4 = new PlataClient("Carlos", "891", productos, serviciosComprea, servicios);
System.out.println("El cliente "+client1.getNombre()+" tiene que pagar "+client1.calcularTotalFactura());
System.out.println("El cliente "+client2.getNombre()+" tiene que pagar "+client2.calcularTotalFactura());
System.out.println("El cliente "+client3.getNombre()+" tiene que pagar "+client3.calcularTotalFactura());
System.out.println("El cliente "+client4.getNombre()+" tiene que pagar "+client4.calcularTotalFactura());
}
}
\ No newline at end of file
/* Consultar todas las pelculas(film).
? Consultar todas las filas de film_actor donde actor_id es de Johnny
? Consultar todas las filas de film_actor donde actor_id es de Johnny or Penelope
? Consultar todas las filas de film_actor donde actor_id es de Johnny and Penelope
? Consultar todas las filas de film_category donde category_id es en (Action, Comedy)
? Consultar todas las filas de film donde titlle se empieza con A
? Consultar todas las filas de film donde titlle se termina con B
? Consultar todas las filas de payment donde amount es entre 0 y 5.
? Consultar todas las filas de film donde title no es "Analyze Hoosiers" */
select * from film order by title asc;
select * from film_actor fa join actor a on a.actor_id = fa.actor_id where a.first_name like 'Johnny'
select * from film_actor fa join actor a on a.actor_id = fa.actor_id where a.first_name like 'Johnny' or a.first_name like 'Penelope'
select * from film_actor fa join actor a on a.actor_id = fa.actor_id where a.first_name like 'Johnny' and a.first_name like 'Penelope'
select * from film_category fc join category c2 on c2.category_id = fc.category_id where c2.name like 'Action' or c2.name like 'Comedy';
select * from film where title like 'A%';
select * from film where title like '%B';
select * from payment p where p.amount between 0 and 5;
select * from film f where f.title <> 'Analyze Hoosiers';
/*Seleccionar todos los stores con sus respectivas existencias*/
select * from inventory i join store st on st.store_id = i.store_id
select sum(f2.replacement_cost) from film f2 group by(f2.release_year)
/*Obtener todos lo clientes que han rentado una pelicula*/
import java.util.Scanner;
class Stack {
/*
* Clase que representa un stack e implementa el push y el pop del stack. Acepta integers como floats
*/
private int[] stack;
private float[] stackf;
private int capacidad;
private int pointer;
public float[] getStackf() {
return stackf;
}
public void setStackf(float[] stackf) {
this.stackf = stackf;
}
public int getPointer() {
return pointer;
}
public void setPointer(int pointer) {
this.pointer = pointer;
}
public int getCapacidad() {
return capacidad;
}
public void setCapacidad(int capacidad) {
this.capacidad = capacidad;
}
public Stack(int capacidad, int[] stack, float[] stackf){
this.capacidad = capacidad;
this.stack = stack;
this.pointer = capacidad - 1;
this.stackf = stackf;
}
public void push(float number){
if(pointer + 1 == capacidad){
System.out.println("El stack esta a maxima capacidad");
}else{
this.stack[pointer+1] = (int)number;
this.stackf[pointer+1] = number;
pointer++;
}
}
public void push(int number){
if(pointer + 1 == capacidad){
System.out.println("El stack esta a maxima capacidad");
}else{
this.stack[pointer+1] = number;
this.stackf[pointer+1] = (float)number;
pointer++;
}
}
public float pop(){
if(pointer - 1 < -1){
System.out.println("Ya no existen datos en el stack");
}else{
pointer--;
return this.stackf[pointer+1];
}
return -1;
}
public int[] getStack() {
return stack;
}
public void setStack(int[] stack) {
this.stack = stack;
}
public void printStack(){
for(int i=pointer;i>=0;i--){
System.out.println(stackf[i]);
}
}
public float getTop(){
return stackf[pointer];
}
public boolean isEmpty(){
if(pointer==-1){
return true;
}
return false;
}
public void ordenarStack(){
float temp;
temp = pop();
System.out.println("pop "+temp);
if(!isEmpty()){
ordenarStack();
}
insertarEnOrder(temp);
}
public void insertarEnOrder(float elem){
if(isEmpty() || elem > getTop()){
push(elem);
}else{
float temp = pop();
insertarEnOrder(elem);
push(temp);
}
}
}
public class StackTest{
public static void main(String[] args){
/*
* Menu de gestion del stack.
* */
int choice = 0;
int cantidad;
int dato;
boolean continuar = true;
Scanner in = new Scanner(System.in);
System.out.println("Ingrese la cantidad de datos de su stack: ");
cantidad = in.nextInt();
int[] datos = new int[cantidad];
float[] datosf = new float[cantidad];
for(int i=0;i<cantidad;i++){
datos[i] = (int)(Math.random()*100);
datosf[i] = (float)datos[i];
}
Stack stack = new Stack(cantidad, datos, datosf);
do{
System.out.println("-------------------\n1 - push()\n2 - pop()\n3 - Imprimir Stack\n4 - Ordenar\n5 - Salir\nEntrada: ");
try{
choice = in.nextInt();
}catch (Exception e){
System.out.println("Entrada no validad");
}
switch (choice){
case 1:
System.out.println("Ingrese un numero: ");
dato = in.nextInt();
stack.push(dato);
break;
case 2:
System.out.println("Pop de : "+stack.pop());
break;
case 3:
System.out.println("Stack Actual: ");
stack.printStack();
break;
case 4:
System.out.println("Stack Ordenado: ");
stack.ordenarStack();
stack.printStack();
break;
case 5:
System.out.println("Saliendo");
continuar = false;
break;
default:
System.out.println("Eleccion no validad");
}
}while(continuar);
}
}
\ No newline at end of file
public class Student {
Notas notas;
public Student(Notas notas){
this.notas = notas;
}
public void preguntarNotas(){
System.out.println("Las notas del estudiante son: ");
int[] notass = notas.getNotas();
for(int nota: notass){
System.out.println(nota);
}
}
public static void main(String[] args){
int[] notasTemp = {2, 3, 4, 5, 4};
Notas notas = new Notas(notasTemp, "Asuncion, Barrio Las Mercedes");
Student estudiante = new Student(notas);
estudiante.preguntarNotas();
}
}
class Notas {
private int[] notas;
private String direccion;
public Notas(int[] notas, String direccion){
this.notas = notas;
this.direccion = direccion;
}
public int[] getNotas() {
return notas;
}
public void setNotas(int[] notas) {
this.notas = notas;
}
private String getDireccion() {
return direccion;
}
public void setDireccion(String direccion) {
this.direccion = direccion;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment