Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Tambahan {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int pilihan = scanner.nextInt();
- scanner.nextLine();
- String inputan = scanner.nextLine();
- String rasa = "";
- boolean isValid = true;
- float harga = 0;
- //set harga dan rasa
- switch (pilihan){
- case 1 -> {
- rasa = "Coklat";
- harga = 47000;
- }
- case 2 -> {
- rasa = "Vanila";
- harga = 58000;
- }
- case 3 -> {
- rasa = "Stroberi";
- harga = 51000;
- }
- default -> isValid = false;
- }
- //check kalo inputan valid
- if (isValid) {//isValid -> isValid == True
- //cek discount pada bulan tertentu
- String bulan = inputan.substring(3,5);
- if (bulan.equals("03")||bulan.equals("05")||bulan.equals("12")){
- harga *=0.8;
- }
- // Set tahun Expired Kue
- String tahun = inputan.substring(6,10);
- int tahunInt = Integer.parseInt(tahun)+1;
- //susun ulang textnya
- String text = inputan.substring(0,6)+tahunInt;
- // print
- System.out.println("=======================");
- System.out.println("Rasa Kue : " + rasa);
- System.out.printf("Harga Kue : Rp%,.2f\n", harga);
- System.out.println("Expired : " + text);
- // atau bisa make printf()
- // int tanggal = Integer.parseInt(inputan.substring(0,2));
- // int bulanInt = Integer.parseInt(bulan);
- // System.out.printf("Expired : %02d/%02d/%d\n",tanggal,bulanInt,tahunInt);
- System.out.println("=======================");
- }else System.out.println("Pilihan Tidak Valid!!!");
- }
- }
Add Comment
Please, Sign In to add comment