+ 1

What's wrong in the code it's not pass case 5

You run a hovercraft factory. Your factory makes ten hovercrafts in a month. Given the number of customers you got that month, did you make a profit? It costs you 2,000,000 to build a hovercraft, and you are selling them for 3,000,000. You also pay 1,000,000 each month for insurance. Task: Determine whether or not you made a profit based on how many of the ten hovercrafts you were able to sell that month. Input Format: An integer that represents the sales that you made that month. Output Format: A string that says 'Profit', 'Loss', or 'Broke Even'. import java.util.Scanner; public class Program { public static void main(String[] args) { int sales; Scanner sc=new Scanner(System.in); sales=sc.nextInt(); if(sales>=10){ System.out.print("Profit"); } else if (sales<10 && sales>=7){ System.out.print("Broke Even"); } else{ System.out.print("Loss"); } } }

24th Dec 2021, 4:42 AM
Leena Patil
2 Antworten
+ 2
The code is basing the monetary result on units rather than on the financial result. if net $ > 0 profit if net $ < 0 loss and if net $ ==0 then broke even.
24th Dec 2021, 5:34 AM
Paul K Sadler
Paul K Sadler - avatar
+ 1
Problem description in simple terms: Factory makes 10 hovercrafts in a month, each one costs 2,000,000 and +insurance 1,000,000 (now find total cost for making) .. (1). And it sold 3,000,000 for each one. (Now find total sold cost for total sales) (2). Check (1) < (2) Profit (1) > (2) Loss Else Broke Even.. edit: what is your logic of sales<10 or >10 ?
24th Dec 2021, 11:27 AM
Jayakrishna 🇮🇳