Siblings Fund Raising Program in java

Question:

Harry, James, Leo, and Sara are siblings and their mother has asked them to sell cake boxes for a fundraising event. She told them that there is a surprise gift for the ones who sell the maximum number of boxes. There can be more than one maximum.

Write a program to display the names of all the siblings who receive gifts by selling the maximum number of boxes. If all the four sold the same number then display, “All get the same gifts.”

Sample input 1:

Enter the number of boxes sold by Sara

14

Enter the number of boxes sold by Harry

14

Enter the number of boxes sold by Leo

14

Enter the number of boxes sold by James

10

Sample output 1:

Sara, Harry and Leo receive the gifts.

Sample input 2:

Enter the number of boxes sold by Sara

14

Enter the number of boxes sold by Harry

14

Enter the number of boxes sold by Leo

14

Enter the number of boxes sold by James

20

Sample output 2:

James receives the gifts.

CODE:

import java.util.*;

     public class Main{
         public static void main (String[] args) {
             Scanner sc= new Scanner(System.in);
             System.out.println("Enter the number of boxes sold by Sara");
             int Sara = sc.nextInt();
             System.out.println("Enter the number of boxes sold by Harry");
             int Harry = sc.nextInt();
             System.out.println("Enter the number of boxes sold by Leo");
            int Leo = sc.nextInt();
            System.out.println("Enter the number of boxes sold by James");
            int James = sc.nextInt();
            if(Sara==Harry && Harry == Leo && Leo==James){
                System.out.println("All get the same gifts");
                System.exit(0);
            }
            if(Sara==Harry && Harry==Leo && Leo>James){
                System.out.println("Sara, Harry and Leo receive the gifts.");
                System.exit(0);
            }
            if(Sara== James && Leo == James && James> Harry){
                System.out.println("Sara, Leo and James receive the gifts.");
                System.exit(0);
            }
            if(Sara== Harry && Harry== James && James>Leo){
                System.out.println("Sara, Harry and James receive the gifts.");
                System.exit(0);
            }
            if(Harry==James && Leo==James && James>Sara){
                System.out.println("Sara, Harry and James receive the gifts.");
                System.exit(0);
            }
            if(Sara == Harry && Harry>Leo && Harry>James){
                System.out.println("Sara and Harry receive the gifts.");
            }
            else if (Sara == Leo && Leo>Harry && Leo>James ){
                System.out.println("Sara and Leo receive the gifts.");
            } 
            else if(Sara == James && James>Harry & James>Leo){
                System.out.println("Sara and James receive the gifts.");
            }
            else if(Harry== Leo && Leo>Sara && Leo>James){
                System.out.println("Harry and Leo receive the gifts.");
            }
            else if (Harry==James && James>Sara && James>Leo){
                System.out.println("Harry and James receive the gifts.");
            } 
            else if(Leo == James && Leo>Harry && Leo>Sara){
                System.out.println("Leo and James receive the gifts.");
            }
            else if(Sara>Harry && Sara>James && Sara>Leo){
                System.out.println("Sara receives the gifts.");
            }
            else if (Harry>Sara && Harry>Leo && Harry>James){
                System.out.println("Harry receives the gifts.");
            } 
            else if (Leo >Sara && Leo>Harry && Leo>James){
                System.out.println("Leo receives the gifts.");
            } 
            else if (James>Sara && James>Harry && James>Leo){
                System.out.println("James receives the gifts.");
            } 
        }
    }

Leave a Comment

Scroll to Top