I made the "Sunshine Ikezaki game" I saw on Twitter in Java.

When such a tweet came to TL, I felt the atmosphere of Zundokokiyoshi, so I implemented it in Java.

Musume I thought about the game with 5 years old. The title is "Sunshine Ikezaki Game". The rules are simple. If you sing a song and get "i", just change it to "yes!". Musume 5 years old "Big old-fashioned Yeah !, Uncle Yeah! San's Toke Yeah !!" I laughed. https://twitter.com/ziuziu/status/918070729341587457

As a specification -If there is "i" or "i" in the entered character string, replace it with "yes". ・ If "i" and "i" are consecutive, replace the second and subsequent times with "-".

Click here for its implementation Maybe it was because I made it at the end of work. It's a pretty dirty code, but ... (~~ This is your ability ~~)

import java.util.Arrays;

public class Yeah {
    /**
     *If "i" or "i" matches the entered character string, replace it with "yes".
     *However, if it is continuous, replace it with "-" from the second time onward.
     */
    public String convert(String text) {
        boolean alwaysHit = false;
        String[] hit = {"I", "I"};
        String[] strArray = toArray(text);
        for (int i = 0; i <= strArray.length - 1; i++) {
            if (Arrays.asList(hit).contains(strArray[i])){
                if (alwaysHit == false) {
                    strArray[i] = "Yeah";
                    alwaysHit = true;
                } else {
                    strArray[i] = "-";
                }
            }else{
                alwaysHit = false;
            }
        }
        return Arrays.toString(strArray).replace(" ", "").replace(",", "").replace("[", "").replace("]", "");
    }

    private String[] toArray(String str) {
        String[] returnStr = new String[str.length()];
        //Turn by the length of the variable str
        for (int i = 0; i <= str.length() - 1 ; i++) {
            //Store in sequence in an array
            returnStr[i] = String.valueOf(str.charAt(i));
        }
        return returnStr;
    }
}

Write the following test code and execute the above code

import static org.junit.Assert.*;

import org.junit.Test;

public class YeahTest {

	@Test
	public void testConverter() {
		Yeah yeah = new Yeah();
		assertEquals("Yeah yeah yeah yeah yeah", yeah.convert("Good good good yeah yeah yeah good"));
		assertEquals("Yeah yeah yeah yeah yeah yeah yeah yeah yeah", yeah.convert("Yeah yeah yeah yeah yeah yeah"));
		assertEquals("Singing Yen Finity", yeah.convert("Singing Infinity"));
	}

}

image.png I've done what I want to do, so now ... I'm going to sleep. (˘ω˘) Sue

Recommended Posts

I made the "Sunshine Ikezaki game" I saw on Twitter in Java.
I made a rock-paper-scissors game in Java (CLI)
I made a simple calculation problem game in Java
I made roulette in Java.
I made an annotation in Java.
Age guessing game made in Java
I tried the new era in Java
I made a primality test program in Java
I touched on the new features of Java 15
I stumbled on the Java version in Android Studio, so I will summarize it
[Android Studio] I want to set restrictions on the values registered in EditText [Java]
I tried to implement the Euclidean algorithm in Java
[Java] I tried to make a rock-paper-scissors game that beginners can run on the console.
I made a program in Java that solves the traveling salesman problem with a genetic algorithm
I made the server side of an online card game ①
I translated [Clone method for Java arrays] as the Clone method in Java arrays.
[Java] ArrayList → Should I specify the size in array conversion?
[Beginner] I made a program to sell cakes in Java
How to switch Java in the OpenJDK era on Mac
I want to simplify the conditional if-else statement in Java
[Java] I implemented the combination.
I studied the constructor (java)
I tried metaprogramming in Java
I tried to illuminate the Christmas tree in a life game
I opened the menu bar (option menu) on Android and saw it.
I recently made a js app in the rumored Dart language
[Java] I want to perform distinct with the key in the object
I tried to display the calendar on the Eclipse console using Java.
I summarized the flow until implementing simple_calendar in Ruby on Rails.
Access the network interface in Java
I sent an email in Java
Guess the character code in Java
Rock-paper-scissors game for beginners in Java
I created a PDF in Java.
I made a shopify app @java
Specify the java location in eclipse.ini
Unzip the zip file in Java
I wrote Goldbach's theorem in java
Notes on signal control in Java
Consideration on the 2017 Java Persistence Framework (1)
I tried the Java framework "Quarkus"
Parsing the COTOHA API in Java
I tried using JWT in Java
Sample vending machine made in Java
Call the super method in Java
[Java] Display the bit string stored in the byte type variable on the console
A note on the differences between interfaces and abstract classes in Java
What wasn't fair use in the diversion of Java APIs on Android
I called the COTOHA API parser 100 times in Java to measure performance.
I want to get the IP address when connecting to Wi-Fi in Java