Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class FruitShop {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String fruit = scanner.nextLine();
- String dayOfWeek = scanner.nextLine();
- double quantity = Double.parseDouble(scanner.nextLine());
- double price = 0.0;
- double totalPrice = 0.0;
- boolean isTrue = dayOfWeek.equals("Monday") || dayOfWeek.equals("Tuesday")
- || dayOfWeek.equals("Wednesday") || dayOfWeek.equals("Thursday")
- || dayOfWeek.equals("Friday");
- boolean weekend = dayOfWeek.equals("Saturday") || dayOfWeek.equals("Sunday");
- if ("banana".equals(fruit)) {
- if (isTrue) {
- price = 2.5;
- } else if (weekend) {
- price = 2.7;
- }
- } else if ("apple".equals(fruit)) {
- if (isTrue) {
- price = 1.2;
- } else if (weekend) {
- price = 1.25;
- }
- } else if ("orange".equals(fruit)) {
- if (isTrue) {
- price = 0.85;
- } else if (weekend) {
- price = 0.9;
- }
- } else if ("grapefruit".equals(fruit)) {
- if (isTrue) {
- price = 1.45;
- } else if (weekend) {
- price = 1.60;
- }
- } else if ("kiwi".equals(fruit)) {
- if (isTrue) {
- price = 2.7;
- } else if (weekend) {
- price = 3.00;
- }
- } else if ("pineapple".equals(fruit)) {
- if (isTrue) {
- price = 5.5;
- } else if (weekend) {
- price = 5.6;
- }
- } else if ("grapes".equals(fruit)) {
- if (isTrue) {
- price = 3.85;
- } else if (weekend) {
- price = 4.2;
- }
- }
- if (price != 0) {
- totalPrice = price * quantity;
- System.out.printf("%.2f", totalPrice);
- } else {
- System.out.println("error");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment