commit

parents
package com.bootcamp20_10.carteles;
public class Cartel {
private Forma forma;
private String text;
public Cartel(Forma forma, String text){
this.forma = forma;
this.text = text;
}
public void rellenarForma(){
if(forma.cuadroFixText(this.text)){
if(forma instanceof Rectangulo){
System.out.println("Se a rellenado el cuadrado exitosamente.");
}else{
System.out.println("Se a rellenado el circulo exitosamente.");
}
}else{
System.out.println("No se a podido rellenar la forma, falta espacio");
}
}
}
package com.bootcamp20_10.carteles;
public class Circulo implements Forma{
private float radio;
private String color;
public Circulo(float radio, String color) {
this.radio = radio;
this.color = color;
}
public float getRadio() {
return radio;
}
public void setRadio(float radio) {
this.radio = radio;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
@Override
public boolean cuadroFixText(String text) {
System.out.println("Forma: Circulo\nEspacio: "+this.radio*2+"\nLongitud Texto: "+text.length());
return text.length() <= radio*2;
}
}
package com.bootcamp20_10.carteles;
public interface Forma {
public boolean cuadroFixText(String text);
}
package com.bootcamp20_10.carteles;
public class Main {
public static void main(String[] args){
Forma rectangulo = new Rectangulo(10f, 5f, "Azul");
Forma ciculo = new Circulo(9.2f, "Amarillo");
Cartel cartel1 = new Cartel(rectangulo, "Atencion Escuela");
Cartel cartel2 = new Cartel(ciculo, "Atencion Escuela");
cartel1.rellenarForma();
cartel2.rellenarForma();
}
}
package com.bootcamp20_10.carteles;
public class Rectangulo implements Forma{
private float longitud;
private float ancho;
private String color;
public Rectangulo(float longitud, float ancho, String color){
this.longitud = longitud;
this.ancho = ancho;
this.color = color;
}
@Override
public boolean cuadroFixText(String text) {
System.out.println("Forma: Rectangulo\nEspacio: "+this.longitud+"\nLongitud Texto: "+text.length());
return text.length() <= longitud;
}
public float getLongitud() {
return longitud;
}
public void setLongitud(float longitud) {
this.longitud = longitud;
}
public float getAncho() {
return ancho;
}
public void setAncho(float ancho) {
this.ancho = ancho;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
}
--Consulta todos los clientes que han alquilado pelculas
select distinct c.customer_id, c.first_name, c.last_name
from customer c
right join rental r on r.customer_id = c.customer_id
order by c.customer_id desc;
--Obtenga todos los clientes que hayan vencido la fecha de vencimiento de pago.Muestra tambin por qu pelculas vencen sus pagos.
select distinct f.film_id, c.customer_id, c.first_name, f.title from customer c
right join rental r on r.customer_id = r.customer_id
right join inventory i on i.inventory_id = r.inventory_id
right join film f on f.film_id = i.film_id
where r.return_date < current_date ;
--Cules son las categoras ms alquiladas?
select c.name, count(c.category_id) from category c
join film_category fc ON fc.category_id = c.category_id
join film f on f.film_id = fc.film_id
join inventory i on i.film_id = f.film_id
join rental r on r.inventory_id = i.inventory_id
group by(c.category_id)
order by count(c.category_id) desc;
--Cuales son las categoras ms alquiladas agrupadas por cliente.
select c2.customer_id, c2.first_name, c.name, count(c.category_id) from category c
join film_category fc ON fc.category_id = c.category_id
join film f on f.film_id = fc.film_id
join inventory i on i.film_id = f.film_id
join rental r on r.inventory_id = i.inventory_id
join customer c2 on r.customer_id = c2.customer_id
group by(c2.customer_id , c.category_id)
order by customer_id, count(c.category_id) desc;
--Cual es el lenguaje ms alquilado
select l.language_id, l.name, count(rental_id) from language l
join film f ON f.language_id = l.language_id
join inventory i on i.film_id = f.film_id
join rental r on r.inventory_id = i.inventory_id
group by (l.language_id)
order by count(r.rental_id) desc
limit 1;
--Cul empleados son los mejores. Significa cual empleados se alquila maximo pelculas.
select s.staff_id, s.first_name, count(r.rental_id) from staff s
join rental r on r.staff_id = s.staff_id
group by(s.staff_id)
order by count(r.rental_id) desc;
--Quin es el actor ms famoso. Significa pelculas de cual actor se alquila maximo.
select a.actor_id, a.first_name, a.last_name, count(r.rental_id) from actor a
join film_actor fa on fa.actor_id = a.actor_id
join film f on f.film_id = fa.film_id
join inventory i on i.film_id = f.film_id
join rental r on r.inventory_id = i.inventory_id
group by(a.actor_id)
order by count(r.rental_id) desc
limit 1;
--Quien es el mejor cliente. Significa quien alquila mximo?
select c.customer_id, c.first_name, c.last_name, count(r.rental_id) from customer c
join rental r on r.customer_id = c.customer_id
group by(c.customer_id)
order by count(r.rental_id) desc
limit 1;
<!DOCTYPE html>
<html lang="en">
<head>
<style>
table, td{
border: 1px solid black;
}
td{
width: 100px;
height: 25px;
text-align: center;
font-family: "Lucida Console", "Courier New", monospace;
}
#screen{
width: 250px;
text-align: right;
}
#divisor{
width: 100px;
}
body {
background: #555;
}
.content {
max-width: 500px;
margin: auto;
background: white;
padding: 10px;
}
</style>
<meta charset="UTF-8">
<title>Calculadora</title>
</head>
<body>
<div class="content">
<table>
<tr>
<td id="screen"></td>
<td id="divisor">/</td>
<td id="cc">CE</td>
</tr>
</table>
<table>
<tr>
<td id="siete">7</td>
<td id="ocho">8</td>
<td id="nueve">9</td>
<td id="mas">+</td>
</tr>
<tr>
<td id="cuatro">4</td>
<td id="cinco">5</td>
<td id="seis">6</td>
<td id="menos">-</td>
</tr>
<tr>
<td id="uno">1</td>
<td id="dos">2</td>
<td id="tres">3</td>
<td id="mult">*</td>
</tr>
<tr>
<td id="dcero">00</td>
<td id="cero">0</td>
<td id="punto">.</td>
<td id="result">=</td>
</tr>
</table>
</div>
</body>
<script>
(function calculadora() {
//Cargamos todos las teclas de la calculadora y tambien el screen
const screen = document.querySelector('#screen');
const divisor = document.querySelector('#divisor');
const suma = document.querySelector('#mas');
const resta = document.querySelector('#menos');
const multiplicacion = document.querySelector('#mult');
const uno = document.querySelector('#uno');
const dos = document.querySelector('#dos');
const tres = document.querySelector('#tres');
const cuatro = document.querySelector('#cuatro');
const cinco = document.querySelector('#cinco');
const seis = document.querySelector('#seis');
const siete = document.querySelector('#siete');
const ocho = document.querySelector('#ocho');
const nueve = document.querySelector('#nueve');
const cero = document.querySelector('#cero');
const doble_cero = document.querySelector('#dcero');
const punto = document.querySelector('#punto');
const igual = document.querySelector('#result');
const ce = document.querySelector('#cc');
//Esta variable nos servira para guardar numero, operador, numero, respectivamente.
let params = ["", "", ""];
let current_param = 0;
//EventListener que escucha por teclas presionadas para ejecutar en la calculadora
document.addEventListener("keypress", function onPress(event) {
switch (event.key){
case "1":
params[current_param] += "1";
writeScreen(params)
break;
case "2":
params[current_param] += "2";
writeScreen(params)
break;
case "3":
params[current_param] += "3";
writeScreen(params)
break;
case "4":
params[current_param] += "4";
writeScreen(params)
break;
case "5":
params[current_param] += "5";
writeScreen(params)
break;
case "6":
params[current_param] += "6";
writeScreen(params)
break;
case "7":
params[current_param] += "7";
writeScreen(params)
break;
case "8":
params[current_param] += "8";
writeScreen(params)
break;
case "9":
params[current_param] += "9";
writeScreen(params)
break;
case "0":
if(!(screen.innerHTML.length === 1 && screen.innerHTML.includes("0"))){
params[current_param] += "0";
writeScreen(params);
}
break;
case "+":
escribeOperador("+");
break;
case "-":
escribeOperador("-");
break;
case "*":
escribeOperador("*");
break;
case "/":
escribeOperador("/");
break;
case "=":
if(current_param===2){
darResultado();
}
break;
case "Enter":
if(current_param===2){
darResultado();
}
break;
default:
console.log(event.key);
}
});
//Limpiar pantalla, y dejar en estado iniciado la calculadora
ce.addEventListener("click", ()=>{
params = ["", "", ""];
current_param = 0;
writeScreen(params);
})
uno.addEventListener("click", ()=>{
params[current_param] += "1";
writeScreen(params);
})
dos.addEventListener("click", ()=>{
params[current_param] += "2";
writeScreen(params);
})
tres.addEventListener("click", ()=>{
params[current_param] += "3";
writeScreen(params);
})
cuatro.addEventListener("click", ()=>{
params[current_param] += "4";
writeScreen(params);
})
cinco.addEventListener("click", ()=>{
params[current_param] += "5";
writeScreen(params);
})
seis.addEventListener("click", ()=>{
params[current_param] += "6";
writeScreen(params);
})
siete.addEventListener("click", ()=>{
params[current_param] += "7";
writeScreen(params);
})
ocho.addEventListener("click", ()=>{
params[current_param] += "8";
writeScreen(params);
})
nueve.addEventListener("click", ()=>{
params[current_param] += "9";
writeScreen(params);
})
doble_cero.addEventListener("click", ()=>{
if(screen.innerHTML.length !== 0
&& !(screen.innerHTML.length === 1 && screen.innerHTML.includes("0"))){
params[current_param] += "00";
writeScreen(params);
}
})
cero.addEventListener("click", ()=>{
if(!(screen.innerHTML.length === 1 && screen.innerHTML.includes("0"))){
params[current_param] += "0";
writeScreen(params);
}
})
punto.addEventListener("click", ()=>{
if(!screen.innerHTML.includes(".")){
params[current_param] += ".";
writeScreen(params);
}
})
suma.addEventListener("click", ()=>{
escribeOperador("+")
});
resta.addEventListener("click", ()=>{
escribeOperador("-")
});
multiplicacion.addEventListener("click", ()=>{
escribeOperador("*")
});
divisor.addEventListener("click", ()=>{
escribeOperador("/")
});
igual.addEventListener("click", ()=>{
if(current_param===2){
darResultado();
}
})
//Funcion que administra el funcionamiento de presionar =
let darResultado = ()=> {
let param1 = Number(params[0]);
let param2 = Number(params[2]);
let resultado;
switch (params[1]) {
case "+":
resultado = (param1 + param2).toFixed(2);
break;
case "-":
resultado = (param1 - param2).toFixed(2);
break;
case "*":
resultado = (param1 * param2).toFixed(2);
break;
case "/":
resultado = (param1 / param2).toFixed(2);
break;
default:
}
params[0] = ""+resultado;
current_param = 0;
params[1] = "";
params[2] = "";
writeScreen(params);
}
//Funcion que administra el funcionamiento de presionar un operador.
function escribeOperador(operador){
if(screen.innerHTML.length !== 0){
if(current_param === 0){
current_param = 2;
params[1] += operador;
writeScreen(params);
}else if(current_param === 2){
let param1 = Number(params[0]);
let param2 = Number(params[2]);
let resultado;
switch (params[1]) {
case "+":
resultado = (param1 + param2).toPrecision(2);
break;
case "-":
resultado = (param1 - param2).toPrecision(2);
break;
case "*":
resultado = (param1 * param2).toPrecision(2);
break;
case "/":
resultado = (param1 / param2).toPrecision(2);
break;
default:
}
params[0] = ""+resultado;
current_param = 2;
params[1] = operador;
params[2] = "";
writeScreen(params);
}
}
}
})()
function writeScreen(params){
const screen = document.querySelector('#screen');
screen.innerHTML = ""+params[0]+params[1]+params[2];
}
</script>
</html>
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