Try to implement Yubaba in Java

Introduction

This article is a ** story post ** based on what I came up with on the train. Please forgive me because it is not a written description of any technology. Then this article could be a spoiler for the movie "Spirited Away". Only people who say "OK!" Should go down.

code

Yubaba.java


import java.util.Scanner;
import java.util.Random;

public class Yubaba {
	public static void main(String[] arts){
		System.out.println("It's a contract. Write your name there.");
		
		Scanner keiyakusho = new Scanner(System.in);
		String name = keiyakusho.nextLine();
		
		System.out.println("Huns."+name +"I mean. It's a luxurious name.");
		
		Random random = new Random();
		int newNameIndex = random.nextInt(name.length());
		String newName = name.substring(newNameIndex,newNameIndex+1);

		System.out.println("From now on your name is"+newName+"It is. Mind you,"+newName+"That's right. I'll reply when I understand"+newName+"!!");
	}
}

Here is the code. If you copy this to Eclipse or IntelliJ, it will work. Although "Implementing Yubaba" does not mean that Yubaba itself is completely reproduced, only the scene where Yubaba hires Chihiro as an employee, which is one of the famous scenes of "Spirited Away", is reproduced. It will be. ~~ I'm sorry for those who expected ~~

Code description

contract

Yubaba first gives you a contract.

import java.util.Scanner;

//~~~~~~
System.out.println("It's a contract. Write your name there.");
		
Scanner keiyakusho = new Scanner(System.in);
String name = keiyakusho.nextLine();

System.out.println("Huns."+name +"I mean. It's a luxurious name.");

Use the Scanner class to take name input from the console and save it in a variable.

Steal the name

Next, Yubaba robs her name.

import java.util.Random;

//~~~~~~

Random random = new Random();
int newNameIndex = random.nextInt(name.length());
String newName = name.substring(newNameIndex,newNameIndex+1);

A random number is generated with 0 or more and less than 0 (the number of input characters), and one character is randomly selected from the input character string and extracted.

System.out.println("From now on your name is"+newName+"It is. Mind you,"+newName+"That's right. I'll reply when I understand"+newName+"!!");

Then give the extracted character as a new name.

Execution result

スクリーンショット 2020-10-30 13.24.09.jpeg

bonus

Someone who is savvy or savvy in Java may have noticed it when they saw the full code. "Hey, this guy" ** If the name input is blank ** "I haven't written the process." That's right. This code ** doesn't dare to write what to do if the name is blank **. So if you leave the name input blank, it's a little programmer-like material code that ** Yubaba crashes **. ~~ A power word called Crash Yubaba ~~ スクリーンショット 2020-10-30 13.19.33 2.png Yubaba seems to be interesting, like a crash. Also, even in the movie, there was no line when the name input was blank, so please forgive me because it is more faithful to the movie if I do not do so (desperate excuse). ~~ I didn't crash ~~

Finally

Thank you for reading this far. I tried to implement Yubaba in Java, so I implemented Ja Auntie. All the content is over with the story, but I hope you can read it. ~~ If you are killed by Ghibli fan or Tetsuko Kuroyanagi, please pick up only the bones ~~

Recommended Posts

Try to implement Yubaba in Java
Try to implement Yubaba in Ruby
How to implement date calculation in Java
How to implement Kalman filter in Java
Try to solve Project Euler in Java
How to implement coding conventions in Java
Try to create a bulletin board in Java
I tried to implement deep learning in Java
Try to implement TCP / IP + NIO with JAVA
Try implementing Yubaba in Kinx
Try using RocksDB in Java
Try calling JavaScript in Java
Try functional type in Java! ①
Implement two-step verification in Java
Implement Basic authentication in Java
Implement math combinations in Java
2 Implement simple parsing in Java
Implement Email Sending in Java
Implement functional quicksort in Java
[Java] How to implement multithreading
Implement rm -rf in Java.
Implement XML signature in Java
I tried to implement Firebase push notification in Java
Try to solve a restricted FizzBuzz problem in Java
Summary of how to implement default arguments in Java
I tried to implement the Euclidean algorithm in Java
Implement Table Driven Test in Java 14
Try implementing Android Hilt in Java
[Introduction to Computer Science No. 0: Try Machine Learning] Let's implement k-means clustering in Java
Implement Thread in Java and try using anonymous class, lambda
Try implementing GraphQL server in Java
3 Implement a simple interpreter in Java
Multithreaded to fit in [Java] template
Try to implement iOS14 Widget function
How to learn JAVA in 7 days
Try running Selenuim 3.141.59 in eclipse (java)
Implement reCAPTCHA v3 in Java / Spring
Implement PHP implode function in Java
Try an If expression in Java
Try to extract java public method
How to use classes in Java?
Try running AWS X-Ray in Java
1 Implement simple lexical analysis in Java
How to concatenate strings in java
How to implement a job that uses Java API in JobScheduler
Interface Try to make Java problem TypeScript 7-3
How to implement search functionality in Rails
Multilingual Locale in Java How to use Locale
Implement API Gateway Lambda Authorizer in Java Lambda
Easy to make Slack Bot in Java
Java reference to understand in the figure
Try using the Stream API in Java
How to do base conversion in Java
Try using JSON format API in Java
Try calling the CORBA service in Java 11+
Try to implement login function with Spring-Boot
Convert SVG files to PNG files in Java
Try making a calculator app in Java
Try to implement UIAlertController by separating files
How to get the date in java
Implement something like a stack in Java