0% found this document useful (0 votes)
63 views10 pages

Practica Desarrollada 2

The document contains code for 5 programming problems: 1) solving a system of linear equations using Cramer's rule, 2) finding the intersection point of two lines, 3) locating the position of the largest element in a 2D array, 4) modifying a banking account class, and 5) creating an ATM machine simulation using an array of accounts. The code includes classes for accounts, methods for deposits, withdrawals, and calculating interest, and uses input/output with the Scanner class.

Uploaded by

Elvis F. Coronel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views10 pages

Practica Desarrollada 2

The document contains code for 5 programming problems: 1) solving a system of linear equations using Cramer's rule, 2) finding the intersection point of two lines, 3) locating the position of the largest element in a 2D array, 4) modifying a banking account class, and 5) creating an ATM machine simulation using an array of accounts. The code includes classes for accounts, methods for deposits, withdrawals, and calculating interest, and uses input/output with the Scanner class.

Uploaded by

Elvis F. Coronel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Pregunta 1:

Código:

package cramer;
import java.util.Scanner;

public class Cramer {


public static void main(String[] args) {
Scanner input = new Scanner(System.in);

System.out.print("Ingrese los valores de: a, b, c, d, e, f: ");


double a = input.nextDouble();
double b = input.nextDouble();
double c = input.nextDouble();
double d = input.nextDouble();
double e = input.nextDouble();
double f = input.nextDouble();

if (a * d - b * c == 0)
System.out.println("La ecuacion no tiene solucion. ");
else
{
double x = (e * d - b * f) / (a * d - b * c);
double y = (a * f - e * c) / (a * d - b * c);
System.out.println("x es " + x + ", y es " + y);
}
}
}
IMPRESIÓN:
Pregunta 2:

Código:

package ejerciciogeom;

import java.util.Scanner;

public class EjercicioGeom {


public static void main(String[] args) {
Scanner input = new Scanner(System.in);

System.out.print("Ingrese: x1, y1, x2, y2, x3, y3, x4, y4: ");
double x1 = input.nextDouble();
double y1 = input.nextDouble();
double x2 = input.nextDouble();
double y2 = input.nextDouble();
double x3 = input.nextDouble();
double y3 = input.nextDouble();
double x4 = input.nextDouble();
double y4 = input.nextDouble();

// Calculate the intersecting point


// Get a, b, c, d, e, f
double a = y1 - y2;
double b = -1 * (x1 - x2);
double c = y3 - y4;
double d = -1 * (x3 - x4);
double e = (y1 - y2) * x1 - (x1 - x2) * y1;
double f = (y3 - y4) * x3 - (x3 - x4) * y3;

// Display results
if (a * d - b * c == 0)
{
System.out.println("Las dos lineas son paralelas ");
}
else
{
double x = (e * d - b * f) / (a * d - b * c);
double y = (a * f - e * c) / (a * d - b * c);
System.out.println("El punto de interseccion es (" + x + ", " + y + ")");
}
}
}
Impresión:
Problema 3

Código:

package posicion;
import java.util.Scanner;
public class Posicion {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);

System.out.print("Ingrese el numero de filas y columnas del arreglo: ");


int rows = in.nextInt();
int columns = in.nextInt();
double[][] userArray = new double[rows][columns];
System.out.println("Ingrese el arreglo");
for (int i = 0; i < userArray.length; i++) {
for (int j = 0; j < userArray[i].length; j++) {
userArray[i][j] = in.nextDouble();
}
}

int[] location = locateLargest(userArray);


System.out.printf("La posicion del mayor elemento 45 es (%d, %d)%n",
location[0], location[1]);
}

public static int[] locateLargest(double[][] a) {


int[] location = new int[]{0, 0};
double largest = a[0][0];
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
if (largest < a[i][j]) {
largest = a[i][j];
location[0] = i;
location[1] = j;
}
}
}
return location;
}
}
Impresión:
Pregunta 4// cambiar solo la variable acont:

Código:

public class Cuenta {


public static void main(String[] args) {
Account account = new Account(1122, 20000);
account.setAnnualInterestRate(4.5);
account.withdraw(2500.0);
account.deposit(3000.0);
System.out.println("Saldo: $" + account.getBalance());
System.out.println("Interes Mensual: " + account.getMonthlyInterest());
System.out.println("Fecha de creacion: " + account.getDateCreated());

}
}

class Account {
private int id = 0;
private double balance = 0.0;
private static double annualInterestRate = 0.0;
private java.util.Date diacreado;

public Account() {
diacreado = new java.util.Date();
}

public Account(int id, double balace) {


this();
this.id = id;
this.balance = balance;
}

public int getId() {


return this.id;
}

public double getBalance() {


return this.balance;
}

public double getAnnualInterestRate() {


return annualInterestRate;
}

public String getDateCreated() {


return this.diacreado.toString();
}

public void setId(int id) {


this.id = id;
}
public void setBalance(double balance) {
this.balance = balance;
}

public void setAnnualInterestRate(double annualInterestRate) {


this.annualInterestRate = annualInterestRate;
}

public double getMonthlyInterestRate() {


return (annualInterestRate / 100) / 12 ;
}

public double getMonthlyInterest() {


return balance * getMonthlyInterestRate();
}

public void withdraw(double amount) {


this.balance -= amount;
}

public void deposit(double amount) {


this.balance += amount;
}
}

Impresión:
Pregunta 5:

package account;

import java.util.Scanner;

public class Cajero {


private static final Scanner in = new Scanner(System.in);

public static void main(String[] args) {


Account[] accounts = new Account[10];
for (int i = 1; i < 11; i++) {
accounts[i - 1] = new Account(i, 100.0);
}

System.out.print("Ingrese un id del 1 al 10 ");


int id = in.nextInt();

if (id < 1 || id > 10) {


id = incorrectId(id);
}

while (true) {
menuDisplay();
System.out.print("Ingrese una opcion ");
int choice = in.nextInt();

if (choice == 4) {
System.out.printf("%nIngrese un id del 1 al 10: ");
id = in.nextInt();

if (id < 1 || id > 10) {


id = incorrectId(id);
}
}
performChoice(id, choice, accounts);
}
}

public static int incorrectId(int id) {


//Scanner in = new Scanner(System.in);
while (id < 1 || id > 10) {
System.out.print("Por favor ingrese un id valido ");
id = in.nextInt();
System.out.println();
}
return id;
}

public static void performChoice(int id, int choice, Account[] accounts) {


//Scanner in = new Scanner(System.in);
switch (choice) {
case 1:
System.out.printf("El saldo de su cuenta es: $%.1f%n",
accounts[id - 1].getBalance());
break;
case 2:
System.out.print("Ingrese el monto a retirar: ");
accounts[id - 1].withdraw(in.nextDouble());
break;
case 3:
System.out.print("Ingrese el monto a depositar ");
accounts[id - 1].deposit(in.nextDouble());
break;
default:
break;
}
}

public static void menuDisplay() {


System.out.printf("%nMenu Principal%n");
System.out.println("1: Consulta Saldo");
System.out.println("2: Retiro");
System.out.println("3: Deposito");
System.out.println("4: Salir");
}
}

Impresión:

You might also like