Ludo King Program in Java

Alex, Nikil and Sam are three friends playing the ludo game. After completing one round they note their points and at the end of the day they calculate the points. The one who scores the highest will be considered as the winner. Write a Java program to find who scores the highest points and display the output.

Requirements:

  • The points should be between 0 and 50 (both inclusive), else print “<points> is an invalid number’.
  • After finding the winner, print “<Name> scores <Points> points and wins the game”.

Note:

  • In the Sample Input / Output provided, the highlighted text in bold corresponds to the input given by the user, and the rest of the text represents the output.
  • Ensure to follow the object-oriented specifications provided in the question description.
  • Ensure to provide the names for classes, attributes, and methods as specified in the question description.
  • Adhere to the code template, if provided.

Please do not use System.exit(0) to terminate the program.

Sample Input/Output 1:

Enter Alex points

10

Enter Nikil points

12

Enter Sam points

25

Sam scored 25 points and won the game

Sample Input/Output 2

Enter Alex points

10

Enter Nikil points

-5

-5 is an invalid number

Sample Input/Output 3

Enter Alex points

60

60 is an invalid number

Ludo King Program in Java

import java.util.Scanner;
public class Main 
{
public static void main(String[] args)
{
 Scanner sc=new Scanner(System.in);
 
 System.out.println("Enter Alex points");
 int pa=sc.nextInt();
 if (pa<0 || pa>50){
 System.out.println(pa+" is an invalid number");
 System.exit(1);
 }
 
 System.out.println("Enter Nikil points");
 int pn=sc.nextInt();
 if(pn<0 || pn>50){
 System.out.println(pn+" is an invalid number");
 System.exit(1);
 }
 
 System.out.println("Enter Sam points");
 int ps=sc.nextInt();
 if(ps<0 || ps>50){
 System.out.println(ps+" is an invalid number");
 System.exit(1);
 }
 
 if(pa>pn && pa>ps){
 System.out.println("Alex scored "+pa+" points and won the game");
 }
 else if (pn>pa && pn>ps){
 
 System.out.println("Nikil scored "+pn+" points and won the game");
 }
 else{
 System.out.println("Sam scored "+ps+" points and won the game");
 }
 
}
}


Sharing Is Caring

Leave a Comment