Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- /*
- task - puzzle - 2.60 lv, talkingDoll - 3 lv, fluffBear - 4.10 lv, minion - 8.20 lv, truck - 2lv.
- data - if total number of order is 50 or more = 25% discount, 10% of income = rent
- expectation output - remaining income, if money are enough {"Yes! (remaining amount) lv left."}
- else {"Not enough money! (remaining amount) lv needed."} formatted %.2f.
- input - PriceOfTrip double, NumPuzzles, NumTalkingDolls, NumFluffBears, NumMinions, NumTrucks int all
- formula - if else statements. NumOrders > 50 apply discount, if priceTrip < income-rent = yes else no
- */
- Scanner scan = new Scanner(System.in);
- //user input on the console
- double priceOfTrip;
- try{
- priceOfTrip = Double.parseDouble(scan.nextLine());
- } catch (Exception e){
- priceOfTrip=0;
- }
- int numPuzzles;
- try{
- numPuzzles = Integer.parseInt(scan.nextLine());
- } catch (Exception e){
- numPuzzles=0;
- }
- int numTalkingDolls;
- try{
- numTalkingDolls = Integer.parseInt(scan.nextLine());
- } catch (Exception e){
- numTalkingDolls=0;
- }
- int numFluffBears;
- try{
- numFluffBears = Integer.parseInt(scan.nextLine());
- } catch (Exception e){
- numFluffBears=0;
- }
- int numMinions;
- try{
- numMinions = Integer.parseInt(scan.nextLine());
- } catch (Exception e){
- numMinions=0;
- }
- int numTrucks;
- try{
- numTrucks = Integer.parseInt(scan.nextLine());
- } catch (Exception e){
- numTrucks = 0;
- }
- double numToys = numPuzzles + numTalkingDolls + numFluffBears + numMinions + numTrucks;
- double totalIncome = (numPuzzles * 2.60) + (numTalkingDolls * 3) + (numFluffBears * 4.10) + (numMinions * 8.20) + (numTrucks * 2);
- //with discount sale toys > 50
- double discount = 0.25 * totalIncome;
- double finalPriceDiscount = totalIncome - discount;
- double rentDiscount = 0.1 * finalPriceDiscount;
- double profitDiscount = finalPriceDiscount - rentDiscount;
- //without discount toys < 50
- double finalPrice = totalIncome;
- double rent = 0.1 * finalPrice;
- double profit = finalPrice - rent;
- // if logic
- if (numToys > 50)
- {
- if (priceOfTrip <= profitDiscount)
- {
- System.out.printf("Yes! %.2f lv left.", profitDiscount - priceOfTrip);
- } else if (priceOfTrip > profitDiscount) {
- System.out.printf("Not enough money! %.2f lv needed.", priceOfTrip - profitDiscount);
- }
- } else
- if (numToys < 50)
- {
- if (priceOfTrip <= profit)
- {
- System.out.printf("Yes! %.2f lv left.", profit - priceOfTrip);
- } else if (priceOfTrip > profit){
- System.out.printf("Not enough money! %.2f lv needed.", priceOfTrip - profit);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment