Commit 9eb04623 by Javier Ferreira

Initial commit

parent 440f60c6
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package stack;
import java.util.Scanner;
class Stack {
private int[] stack;
private float[] stackjf;
private int cap;
private int puntero;
public float[] getStackf() {
return stackjf;
}
public void setStackf(float[] stackf) {
this.stackjf = stackf;
}
public int getPointer() {
return puntero;
}
public void setPointer(int pointer) {
this.puntero = pointer;
}
public int getCapacidad() {
return cap;
}
public void setCapacidad(int capacidad) {
this.cap = capacidad;
}
public Stack(int capacidad, int[] stack, float[] stackf){
this.cap = capacidad;
this.stack = stack;
this.puntero = capacidad - 1;
this.stackjf = stackf;
}
public void push(float number){
if(puntero + 1 == cap){
System.out.println("El stack esta a maxima capacidad");
}else{
this.stack[puntero+1] = (int)number;
this.stackjf[puntero+1] = number;
puntero++;
}
}
public void push(int number){
if(puntero + 1 == cap){
System.out.println("El stack esta a maxima capacidad");
}else{
this.stack[puntero+1] = number;
this.stackjf[puntero+1] = (float)number;
puntero++;
}
}
public int pop(){
if(puntero - 1 < -1){
System.out.println("Ya no existen datos en el stack");
}else{
puntero--;
return this.stack[puntero+1];
}
return -1;
}
public int[] getStack() {
return stack;
}
public void setStack(int[] stack) {
this.stack = stack;
}
public void printStack(){
for(int i=puntero;i>=0;i--){
System.out.println(stackjf[i]);
}
}
}
/**
*
* @author user
*/
public class Stack1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int choice = 0;
int cantidad;
int dato;
boolean continuar = true;
Scanner in = new Scanner(System.in);
System.out.println("Rellene la pila: ");
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 - Salir\nEntrada: ");
try{
choice = in.nextInt();
}catch (Exception e){
System.out.println("Entrada no validad");
}
switch (choice){
case 1:
System.out.println("Usuario 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("Pila actual: ");
stack.printStack();
break;
case 4:
System.out.println("Salir");
continuar = false;
break;
default:
System.out.println("Eleccion no valida");
}
}while(continuar);
// TODO code application logic here
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package year;
/**
*
* @author user
*/
public class Yearbisiesto {
public static void main(String[] args) {
System.out.println("Mostrar los años bisiestos desde 1960 hasta este año: ");
int bisiesto_year = 1960;
do{
if(bisiesto_year%100 == 0){
if(bisiesto_year%400 == 0){
System.out.println(bisiesto_year);
}
}else{
System.out.println(bisiesto_year);
}
bisiesto_year += 4;
}while(bisiesto_year<2021);
// TODO code application logic here
}
}
/**
* @param args the command line arguments
*/
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package j;
/**
*
* @author user
*/
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("Rellenado completamente.");
}else{
System.out.println("Circulo rellenado.");
}
}else{
System.out.println("No se pudo rellenar la forma, falta espacio");
}
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package j;
/**
*
* @author user
*/
public class Circulo implements Forma {
private float radio;
private float color;
public Circulo(float f, String amarillo) {
this.radio= radio;
this.color= color;
}
public float getRadio() {
return radio;
}
public void setRadio(float radio) {
this.radio = radio;
}
public float getColor() {
return color;
}
public void setColor(float 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;
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package j;
/**
*
* @author user
*/
public interface Forma {
public boolean cuadroFixText(String text);
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package j;
/**
*
* @author user
*/
public class J {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Forma rectangulo = new Rectangulo(8f, 5f, "Azul");
Forma ciculo = new Circulo(9.2f, "Amarillo");
Cartel cartelone = new Cartel(rectangulo, "Atencion Escuela");
Cartel carteltwo = new Cartel(ciculo, "Atencion Escuela");
cartelone.rellenarForma();
carteltwo.rellenarForma();
// TODO code application logic here
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package j;
/**
*
* @author user
*/
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;
// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
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;
}
}
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