Documentos de Académico
Documentos de Profesional
Documentos de Cultura
So Luci On Practica
So Luci On Practica
}
package pregunta_1;
import java.util.Arrays;
import java.util.Random;
public class MatrizFraccion {
Fraccion [][] mf;
public void ordenarMF(){
for (int i = 1; i < mf[0].length; i++) {
for (int j = 0; j < mf.length; j++) {
for (int k = 0; k < mf[0].length; k++) {
for (int l = 0; l < mf.length; l++) {
if (mf[l][k].valorF()>mf[l]
[k+1].valorF()) {
Fraccion aux = mf[l][k];
mf[l][k] = mf[l][k+1];
mf[l][k+1] = aux;
}
}
}
}
}
}
public void sumarC(){
for (int j = 0; j < mf[0].length; j++) {
Fraccion fc = new Fraccion(0,1);
for (int i = 0; i < mf.length; i++) {
fc = fc.sumaF(mf[i][j]);
}
System.out.println("La suma de la Columna " + (j+1) +
" es : " + fc);
fc.simplificarF();
System.out.println("La suma de la Columna " + (j+1) +
" simplificada es : " + fc);
}
}
public void generarM(){
Random r = new Random();
for (int i = 0; i < mf.length; i++) {
for (int j = 0; j < mf[0].length; j++) {
mf[i][j] = new Fraccion(r.nextInt(9)+1,
r.nextInt(9)+1);
}
}
}
@Override
public String toString() {
String s = "\n";
for (int i = 0; i < mf.length; i++) {
for (int j = 0; j < mf[0].length; j++) {
s += mf[i][j] + "\t";
}
s += "\n";
}
}
}
package pregunta_1;
import java.util.Scanner;
public class PruebaMatrizF {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("FILA: ");
int f = sc.nextInt();
System.out.print("COLUMNA: ");
int c = sc.nextInt();
MatrizFraccion mf = new MatrizFraccion(f, c);
mf.generarM();
System.out.println("MATRIZ GENERADA: ");
System.out.println(mf);
System.out.println("SUMA DE LAS COLUMNAS: ");
mf.sumarC();
System.out.println("MATRIZ ORDENADA: ");
mf.ordenarMF();
System.out.println(mf);
}
}
PREGUNTA 2
package pregunta_2;
@Override
public String toString() {
return producto + "\t" + precio;
}
public Producto(String producto, int precio) {
super();
this.producto = producto;
this.precio = precio;
}
public String getProducto() {
return producto;
}
public void setProducto(String producto) {
this.producto = producto;
}
public int getPrecio() {
return precio;
}
public void setPrecio(int precio) {
this.precio = precio;
}
@Override
public int compareTo(Producto o) {
if (producto.compareTo(o.producto)>0) {
return 1;
} else {
if (producto.equals(o.producto)) {
return 0;
}
}
return -1;
}
}
package pregunta_2;
import
import
import
import
java.util.ArrayList;
java.util.Collections;
java.util.Iterator;
java.util.Scanner;
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;
public class PruebaProducto {
static Scanner sc = new Scanner(System.in);
static ArrayList<Producto> productos = new
ArrayList<Producto>();
public static void main(String[] args) {
int opc = 0;
do {
opc = menu();
switch (opc) {
case 1:
System.out.print("PRODUCTO: ");
String producto = sc.next();
System.out.print("PRECIO: ");
int precio = sc.nextInt();
Producto pro = new Producto(producto, precio);
productos.add(pro);
break;
case 2:
System.out.println("PRODUCTO\tPRECIO");
for (Iterator it = productos.iterator(); it
.hasNext();) {
Producto prod = (Producto) it.next();
System.out.println(prod);
}
break;
case 3:
System.out.print("PRODUCTO: ");
producto = sc.next();
System.out.print("PRECIO: ");
precio = sc.nextInt();
pro = new Producto(producto, precio);
System.out.print("Ingrese Posicin del producto
a modificar: ");
int pos = sc.nextInt();
productos.set(pos-1, pro);
break;
case 4:
Collections.sort(productos);
break;
case 5:
System.out.println("FIN DEL PROGRAMA");
break;
default:
System.out.println("OPCIN INCORRECTA");
break;
}
} while (opc != 5);
}
private static int menu() {
System.out.println("MEN DE OPCIONES");
System.out.println("[1] AGREGAR PRODUCTO");
System.out.println("[2] LISTAR PRODUCTOS");
System.out.println("[3] MODIFICAR PRODUCTO");
System.out.println("[4] ORDENAR PRODUCTOS");
System.out.println("[5] SALIR");
}
}
PREGUNTA 3
return 0;
package pregunta_3;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
public class ArrayLista {
ArrayList<Punto> puntos;
public void ordenarPuntos(){
Collections.sort(puntos);
}
}
package pregunta_3;
import java.util.Scanner;
public class PruebaPuntos {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
@Override
public String toString() {
return "(" + x + "," + y + "," + z + ")";
}
public Punto(int x, int y, int z) {
super();
this.x = x;
this.y = y;
this.z = z;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public int getZ() {
return z;
}
public void setZ(int z) {
this.z = z;
}
@Override
public int compareTo(Punto o) {
if (z>o.z) {
return 1;
} else {
if (z == o.z) {
return 0;
}
}
return -1;
}