Advertisement
Harse

Untitled

Apr 24th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Exercise {
  4.  
  5. public static void main(String[] args) {
  6. Scanner scanner=new Scanner(System.in);
  7.  
  8. boolean fair = false;
  9. System.out.println("Enter the number of classmates for class 1: ");
  10. int firstClass=scanner.nextInt();
  11. System.out.println("Enter the number of classmates for class 2: ");
  12. int secondClass=scanner.nextInt();
  13. System.out.println("Enter the number of classmates for class 3: ");
  14. int thirdClass=scanner.nextInt();
  15. System.out.println("How much money have the first class won: ");
  16. double moneyFisrtEarn=scanner.nextDouble();
  17. System.out.println("How much money have the second class won: ");
  18. double moneySecondEarn=scanner.nextDouble();
  19. System.out.println("How much money have the third class won: ");
  20. double moneyThirdEarn=scanner.nextDouble();
  21. System.out.println("How much cost the excursion: ");
  22. int moneyExcursion=scanner.nextInt();
  23.  
  24. if(!fair) {
  25. if(moneyFisrtEarn>moneySecondEarn && moneySecondEarn>moneyThirdEarn) {
  26. fair=true;
  27. }else {
  28. System.out.println("This numbers are not fair. Think again!!!");
  29. fair=false;
  30. }
  31. }
  32. whoWon(firstClass,moneyFisrtEarn,moneyExcursion);
  33. whoWon(secondClass,moneySecondEarn,moneyExcursion);
  34. whoWon(thirdClass,moneyThirdEarn,moneyExcursion);
  35.  
  36.  
  37.  
  38.  
  39. }
  40. static void whoWon(int students,double moneyEa,double moneyEx) {
  41. int seats=(int) (moneyEa/moneyEx);
  42. int remainder=students-seats;
  43. int available=students-remainder;
  44. System.out.println("For the class there are: "+available+ " lucky students and "+ remainder+ " unlucky");
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement