Skip to content

Instantly share code, notes, and snippets.

@ThaiseFreitas
Created May 12, 2025 02:37
Show Gist options
  • Save ThaiseFreitas/6582a419ef138bf962422800e770d62b to your computer and use it in GitHub Desktop.
Save ThaiseFreitas/6582a419ef138bf962422800e770d62b to your computer and use it in GitHub Desktop.
desafioBar.java
package application;
import java.util.Locale;
import java.util.Scanner;
import entities.Bill;
public class Program {
public static void main(String[] args) {
Locale.setDefault(Locale.US);
Scanner sc = new Scanner(System.in);
Bill bill = new Bill();
System.out.println(" Sexo: ");
bill.gender = sc.next().charAt(0);
System.out.println(" Quantidade de cervejas: ");
bill.beer = sc.nextInt();
System.out.println(" Quantidade de refrigerantes: ");
bill.softDrink = sc.nextInt();
System.out.println(" Quantidade de espetinhos: ");
bill.barbecue = sc.nextInt();
System.out.println();
System.out.println("--------RELATÓRIO---------");
System.out.println();
System.out.print(" Consumo = ");
double consumo = bill.feeding();
System.out.printf("R$ %.2f\n ", consumo);
System.out.print("Couvert = R$ ");
if(consumo < 30.00) {
System.out.print(bill.couvert());
}
else {
System.out.print(" 0.0 ");
}
System.out.println();
System.out.print(" Ingresso = R$ ");
double sexo = bill.ticket();
System.out.print(sexo);
System.out.println();
System.out.print(" Valor a pagar = ");
double conta = bill.total();
System.out.printf(" R$ %.2f\n ", conta);
sc.close();
}
}
_______________________________________________________________________________________________________________________________________
package entities;
public class Bill {
public char gender;
public int beer;
public int barbecue;
public int softDrink;
public double feeding() {
return (beer * 5.00) + (barbecue * 7.00) + (softDrink * 3.00);
}
public double ticket() {
if(gender == 'M') {
return 10.00;
}
else {
return 8.00;
}
}
public double couvert() {
return 4.00;
}
public double total() {
return couvert() + feeding() + ticket();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment