×

Program to Implement FLAMES Game in Java

Friends, Lovers, Affectionate, Marriage, Enemies, and Sibling are all represented by the acronym FLAMES, which also serves as the name of a well-known game. Although, it can be entertaining to play with your friends, this game does not effectively determine whether a person is suited for you. So, we are going to learn how to create a program to find what will be the relation between the two names. So, in this article, we are going to know how to write a program for flames game and we also get a brief understanding how the game works.

How does the FLAMES game work?

Following are the sequence of steps by which we can find the relation between two names.

  • Select two names.
  • Eliminate the characters that frequently appear along with those instances.
  • Count the number of characters still available.
  • Think of FLAMES as the letter’s "F", "L", "A", "M", "E," and "S."
  • Using the count, we just received, start eliminating letters.
  • The final letter in the process is the outcome.

Approach for building the program

Two counts are needed for names with initial values of 0, and one counter is needed for flames with initial values of 5. Two strings are used for names, and one is used to keep FLAMES, totaling three strings. Here, the computer calculated the first name's letter count before calculating the second name's letter count. Then, one for loop is executed for each name to count the frequent letters after saving them using strlen into integer variables. After that, each name, which is represented by a string, has its letters removed using stacked if-else statements. To carry out this operation further, the for loop is repeated. Each letter of FLAMES is pointed to because of the counter rotating.

Implementation

Two names will be accepted as input, after which we will delete any common characters that appear often in both names. We will create a user-defined function that will hold a list of characters that correspond to the names of two players and return a list of concatenated lists to eliminate.Once we have deleted all the common characters, the result list will comprise acronyms for "Friends," "Lovers," "Affectionate," "Marriage," "Enemies," and "Siblings." We'll next begin removing words from the list one at a time until there is only one left using the count we received. The term that remains on the list will be the result.

Example:

Input: Player1 is AJAY, while Player2 is PRIYA.

Results: Friends.

We are deleting the letters A and Y from the two names in the example above since they are both instances of common letters that only appear once in each name (common count). The number of letters remaining is now 5, so let's count them all. Using the count, we just received, start deleting letters from FLAMES one at a time. The letter that survives the procedure is the outcome.

  • Circularly, counterclockwise motion is used for counting.
  • FLAMES counting starts from F, and since E is at the fifth count, we erase E and begin counting again from S.
  • FLAMS
  • M is on the fifth count, so we take Mout of the equation and start counting from S.
  • We delete S and start counting with F as FLAS S is on the fifth count.
  • FLA
  • L is on the fifth count; therefore, we take L out of the equation and start counting from A.
  • The fifth count for FA A necessitates A's elimination. This is the final response since there is just one letter left.
  • F
  • Now, F or friends describes the relationship.

Program to implement flames using Java

import java.io.*;
import java.util.*;
public class Flames
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
StringBuffer s1=new StringBuffer(sc.next());
StringBuffer s2=new StringBuffer(sc.next());

char c,d,e='\0';
for(int i=0;i<s1.length();i++)
{
c=s1.charAt(i);
for(int j=0;j<s2.length();j++)
{
d=s2.charAt(j);
if(c==d)
{
s1.deleteCharAt(i);
s2.deleteCharAt(j);
i--;
j--;
break;
}
}
}
s1=s1.append(s2);
int k=6,l=0;
String s3="FLAMES";
while(k>1)
{
for(int m=1;m<s1.length();m++)
{
if(s3.charAt(l)!='X')
{
l++;
if(l==6)
l=0;
}
else
{
l++;
if(l==6)
l=0;
m--;
}
}
while(s3.charAt(l)=='X')
{
l++;
if(l==6)
l=0;
}
s3=s3.substring(0,l)+"X"+s3.substring(l+1);
k--;
}

for(int i=0;i<s3.length();i++)
{
if(s3.charAt(i)!='X')
e=s3.charAt(i);
}
switch(e)
{
case 'F':System.out.println("Friends");
break;
case 'L':System.out.println("Love");
break;
case 'A':System.out.println("Affection");
break;
case 'M':System.out.println("Marriage");
break;
case 'E':System.out.println("Enemy");
break;
case 'S':System.out.println("Sister");
break;
default :break;
}
}
}

Output:

Love

Related Topics

Java String lastIndexOf() method

Java String lastIndexOf() method returns last index of character or substring in a String. Syntax: Method Description int lastIndexOf(int ch)It returns last index position for the given char valueint lastIndexOf(int ch, int...

2 minutes read.

Differences and Similarities between HashSet, LinkedHashSet and TreeSet in Java

HashSet Class: The HashSet is a class that executes the Setpoint of interaction. It is utilised to store the items in a hashtable; a hashtable is an information structure which holds...

10 minutes read.

Cosmic Superclass in Java

The parent class of all Java classes is the Object class. The Java Object class is the parent of all Java classes, whether directly or indirectly. The Object class is...

6 minutes read.

Time Class Operation in Java

The Java SQL package includes the time class. This class is merely a lightweight wrapper for java. util. THANKS TO THE recognize BC API can recognize this as a SQL...

3 minutes read.

Java Byte Keyword

Byte: The Keyword Byte in Java programming language is a primitive data type.Digital content that is most used for eight bits is called as a byte.The Java Byte Keyword is used...

3 minutes read.

Creation of Multi Thread in java

What are threads in Java? We can use threads to facilitate parallel processing. Threads are helpful when you wish to execute several pieces of code concurrently. A thread is a small process...

3 minutes read.

What is interpreter in Java?

The programming language Java is platform-neutral. Therefore, can use Java on any platform that supports the Java processor. The Piece of software transforms the Java bytecode contained in the class...

5 minutes read.

Method chaining in Java

Method chaining in Java is the act of calling a series of methods one after the other. The sole distinction between it and function Object () constructor chaining is the difference...

3 minutes read.

Java Boolean parseBoolean() Method

The parseBoolean() method of Boolean class returns a Boolean value for the specified String argument. It returns true if and only if string’s value is equal to “true”, else it...

1 minute read.

Ramanujan Number or Taxicab Number in Java

In this section, we will discuss what a Ramanujan number (also known as a Hardy-Ramanujan number) is and how to use a Java programme to determine if a given integer...

3 minutes read.

Java AWT

Java AWT Java programming is used to develop different types of applications like window-based applications, web applications, Enterprise applications, or mobile applications. For creating standalone applications, Java AWT API is used....

11 minutes read.

Java Strictfp Keyword

Strictfp is used to impose limits on floating-point calculation. It ensures that we will get the same result on every platform while performing an operation with the floating-point variable. The floating-point calculation is platform-dependent due...

1 minute read.

Accessors and Mutator in Java

Introduction Accessors and mutators are used in Java to get and set the value of private fields, respectively. Accessors and mutators are both referred to as getters and setters, respectively. The...

6 minutes read.

How to install Java in Windows 10

To make programs that can run on our systems, we need to install the programming language related software in our systems. Different programming language requires a different type of software aka...

6 minutes read.

Reserved Keywords in Java

In Java, a reserved term is used as a code key called a keyword. Because they are predefined, these terms cannot be used for anything else. They cannot serve as...

3 minutes read.

How to create a mirror image of a 2D array in Java

Problem Statement We have provided a list of m x n. here m indicates rows, and n indicates columns). Printing the fresh matrices should result in a mirror reflection of an...

2 minutes read.

Java Math max() Method

The max() method of Math class returns the greater of two arguments. The arguments can be of double, float, int or long data type. Syntax: public static double max(double a, double b)public...

2 minutes read.

Java Password Generator

Generally, we must create a strong password for security reasons. In Java, there are numerous strategies for creating secure passwords. We will learn how to create a strong password in...

4 minutes read.

Enterprise Java Beans

One of the many Java APIs for the common development of corporate software is Enterprise Java Beans (EJB). An EJB, a server-side software component, contains the business logic of an...

4 minutes read.

Caesar Cipher Program in Java

It is among the most popular and straightforward encryption methods. With this method, each letter in the text is swapped out for a letter that is a certain number of...

3 minutes read.