×

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

Matrix Multiplication Program in Java

Matrix Multiplication Program in Java The matrix multiplication program in Java is the continuation of the matrix program in Java that we have already discussed earlier. In this section, we will...

3 minutes read.

Package naming convention in Java

It is conceivable that many programmers will use the same name for various types, given that Java programmers from all over the world create classes and interfaces. For illustration, suppose...

4 minutes read.

Int vs Integer in Java

In Java, numerical data can be stored using int or Integer. int and Integer both have different definitions but similar usage in Java. What is int in Java? int is a primitive...

4 minutes read.

Method Overriding in Java

Overriding  Overriding is also known as run time polymorphism, and it is about the same method with the same signatures in different classes. Overriding can be applied only methods. Method Overriding Method Overriding...

8 minutes read.

Generics in Java

Generics in Java Parameterizedtypes mean generic. Generics allow types (Character, Integer, String, …, etc., as well as user-defined types) to act as parameters to interfaces, classes, and methods. Generics in Java...

9 minutes read.

Example of Static import in Java

Static keyword Java's static keyword is mainly used to control memory. Variables, methods, blocks, and nested classes are compatible with the static keyword. Instead of an instance, the static keyword is...

3 minutes read.

Frugal number in Java

A frugal number is a positive integer with base b that has more digits than the number of prime factors it can be factored into (including exponents greater than 1)....

3 minutes read.

Self-Descriptive Numbers in Java

A number n is given. Identifying the self-descriptive numbers that exist between 1 and n is our task. Self-Descriptive Numbers The definition of a self-descriptive number, m, is a number with b...

6 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.

Java Font

The font is a Java class that is a part of java.awt package. The Serializable interface is implemented by it. The direct recognized child of a Java Font class is...

8 minutes read.

Ordinal Number in Java

What is the Ordinal Number in Java? An object's or person's position or rank can be expressed mathematically using an ordinal number. Depending on the criteria used to establish the positions,...

3 minutes read.

Client Server Program in Java

Client Server Program in Java The client and server are the two main components of socket programming. The client is a computer/node that request for the service and the server is...

7 minutes read.

Difference Between Data Hiding and Abstraction in Java

Abstraction: Data Abstraction and Data Hiding ideas are utilised to show the expected data to the end client and conceal the superfluous subtleties, however, for specific purposes like decreasing the framework's...

10 minutes read.

Concurrent Modification Exception In Java

When an object is attempted to be updated concurrently when it is not allowed, the ConcurrentModificationException arises. This error typically occurs while using Java Collection classes. When another thread is iterating...

5 minutes read.

Java Throw and Throws Keyword

Exceptions in Java enable us to construct high-quality programs where faults are checked at compile time rather than run time and where we may define unique exceptions that make code...

6 minutes read.

Check whether Java is installed or not

As we know that there are various operating systems, to check whether Java is installed or not in Windows and Mac we use the following ways.           Windows Operating System: There are several...

2 minutes read.

Tribonacci series in Java

The Fibonacci series and the Tribonacci sequence are linked. The Fibonacci sequence, each element summates the three preceding terms, is expanded into the Tribonacci series in Java. Through specific examples,...

3 minutes read.

Multithreading Program in Java

Multithreading Program in Java: Before discussing multithreading, it is important to discuss threads. Threads are the most fundamental part of a process. A process can have one or more threads....

4 minutes read.

Java String getChars() Method

Java String getChars() method copies characters from current String to the destination character array . Syntax: public void getChars(int srcBeginIndex, int srcEndIndex, char[] destination, int dstBeginIndex) Parameters: srcBegin - index of the first character...

1 minute read.

Automatic Resource Management

In computer programming, resource management refers to the wide set of techniques for the effective management of the system resources. There are two ways of management of resources: The computer program itself...

2 minutes read.