I have a problem that I raised before and as they told me, I need to show code and be more specific, so here I go. I have to introduce the variable precio
by Scanner in a method, and I want to later send that variable precio
to the main
to use it in the 2nd method. On the other hand, I would also like to use only one return
to round two figures, but I don't see how. My code:
import java.util.*;
public class Precios {
public static void main(String[] args) {
Scanner teclado = new Scanner(System.in);
preciosPorcentajes(teclado);
preciosSemanales(teclado, precio);
}
public static void preciosPorcentajes(Scanner teclado) {
System.out.print("Introduce precio: ");
double precio = teclado.nextDouble();
for (int i = 1; i <= 3; i++) {
double porcentaje = 1.0;
double intereses = precio * porcentaje / 100 * i;
System.out.print(i + " años \t" + intereses * (1.0) + "(1.0%) \t" + intereses * (1.5) + "(1.5%) \t");
}
}
public static void preciosSemanales(Scanner teclado, double precio) {
System.out.print("Introduce el Precio anual: ");
double precioAnual = teclado.nextDouble();
System.out.print("Introduce la tasa: ");
double tasas = teclado.nextDouble();
System.out.print("Introduce la duración: ");
int semanas = teclado.nextInt();
for(int i = 1; i <= semanas; i++) {
double intereses = precio * tasaInteres / 100;
intereses = redondear(precio, intereses);
System.out.println("Semana " + i);
System.out.println("\t Precio Anual: " + (precio));
System.out.println("\t Intereses: " + intereses);
precio += intereses + precioAnual;
precio = redondear(precio, intereses);
}
}
public static double redondear(double precio, double intereses) {
double num = Math.round(precio * 100) / 100.0;
double num = Math.round(intereses * 100) / 100.0;
return num;
}
}
Thanks for the help.