I have to do the following exercise:
Make a Java program that requests the total amount spent by the client from a shop, print the payment options, request the desired option, and prints the total value of the installments (if any).
1) Option: the 10% discount view
2) Option: twice (price tag)
3) Option: 3 to 10 times with 3% interest per month (for purchases only above R $ 100.00). Use the Switch command.
I'm having trouble finding where I'm going wrong in the code below:
The error is when I call the switch.
package Prova_A;
import java.util.Scanner;
public class Exe_02 {
Scanner ler = new Scanner(System.in);
int op() {
Scanner ler = new Scanner(System.in);
int op;
System.out.println("*****Modo de Pagamento*****");
System.out.println("1 - Á Vista");
System.out.println("2 - 2 Vezes");
System.out.println("3 - 3 Vezes");
op = ler.nextInt();
System.out.println("*******************************\n");
return (op);
}
float aVista(float vlr) {
System.out.println("Total R$: " + vlr);
System.out.println("Total a pagar R$: " + vlr * 0.9);
return (0);
}
float duasVezes(float vlr) {
System.out.println("Total R$: " + vlr);
System.out.println("Total a pagar R$: " + vlr / 2);
return (0);
}
float tresVezes(float vlr) {
int parcelas;
System.out.println("Total R$: " + vlr);
do {
System.out.println("Informe a quantidade de parcelas :\n");
parcelas = ler.nextInt();
} while ((parcelas > 10) || (parcelas < 3));
System.out.println("Parcelas de R$:\n " + parcelas + (vlr * 1.03) / parcelas);
return (0);
}
public static void main(String[] args) {
Scanner ler1 = new Scanner(System.in);
float vlrCompra;
int opcao;
System.out.println("Informe o total da compra: \n");
vlrCompra = ler1.nextFloat();
System.out.println("***************************\n");
switch(op){
case 1:
System.out.println("Pagamento a vista: \n");
vlrCompra = ler.nextFloat();
break;
}
}
}