Change seats with java

Change seats for 12 men and 8 women in Java

What you want to achieve

・ Arrangement is random ・ I want to place one or more women somewhere in a horizontal row ・ If a person with bad eyesight enters, fix it in front ・ Easy-to-understand code

result

Get out of the shuffled list with get (). Made it look like a seat with System ~ println

・ Arrangement is random → The result changes every time with Collections.shuffle () ・ I want to place one or more women somewhere in a horizontal row → In advance, we decided where to place women and men. ・ Fixing people with bad eyesight → Remove it from the list and delete the "~ get ()" to make it the name of the person to fix.

code


import java.util.ArrayList;
import java.util.Collections;

public class Sekigae4 {
        public static void main(String[] args) {

                ArrayList<String> man = new ArrayList<String>();
                man.add("Male 1");
                man.add("Male 2");
                man.add("Male 3");
                man.add("Male 4");
                man.add("Male 5");
                man.add("Male 6");
                man.add("Male 7");
                man.add("Male 8");
                man.add("Male 9");
                man.add("Male 10");
                man.add("Male 11");
                man.add("Male 12");

                ArrayList<String> woman = new ArrayList<String>();
                woman.add("Female 1");
                woman.add("Woman 2");
                woman.add("Woman 3");
                woman.add("Female 4");
                woman.add("Female 5");
                woman.add("Female 6");
                woman.add("Female 7");
                woman.add("Female 8");

                Collections.shuffle(man);
                Collections.shuffle(woman);

                System.out.println("--After sorting--");
                System.out.println(woman.get(0) + " | " + man.get(0)   + " | " + man.get(1)   + " | "+ man.get(2));
                System.out.println(woman.get(1) + " | " + man.get(3)   + " | " + man.get(4)   + " | "+ woman.get(2));
                System.out.println(man.get(5)   + " | " + man.get(6)   + " | " + man.get(7)   + " | "+ woman.get(3));
                System.out.println(woman.get(4) + " | " + woman.get(5) + " | " + man.get(8)   + " | "+ man.get(9));
                System.out.println(man.get(10)  + " | " + man.get(11)  + " | " + woman.get(6) + " | "+ woman.get(7));
        }
}

Recommended Posts

Change seats with java
Install java with Homebrew
Install Java with Ansible
Comfortable download with JAVA
Switch java with direnv
Download Java with Ansible
Let's scrape with Java! !!
Build Java with Wercker
Endian conversion with JAVA
Easy BDD with (Java) Spectrum?
Use Lambda Layers with Java
Getting Started with Java Collection
Java Config with Spring MVC
Basic Authentication with Java 11 HttpClient
Let's experiment with Java inlining
Run batch with docker-compose with Java batch
[Template] MySQL connection with Java
Rewrite Java try-catch with Optional
Install Java 7 with Homebrew (cask)
[Java] JSON communication with jackson
Java to play with Function
Try DB connection with Java
Change the port with SpringBoot
Change Wordpress siteurl with command
Enable Java EE with NetBeans 9
[Java] JavaConfig with Static InnerClass
Try gRPC with Java, Maven
Let's operate Excel with Java! !!
Version control Java with SDKMAN
RSA encryption / decryption with java 8
Change java encoding in windows
Paging PDF with Java + PDFBox.jar
Sort strings functionally with java
Object-oriented (java) with Strike Gundam
[Java] Content acquisition with HttpCliient
Java version control with jenv
Troubleshooting with Java Flight Recorder
Streamline Java testing with Spock
Connect to DB with Java
Connect to MySQL 8 with Java
Error when playing with java
Using Mapper with Java (Spring)
Java study memo 2 with Progate
Java version change on CentOS
Getting Started with Java Basics
Seasonal display with Java switch
Use SpatiaLite with Java / JDBC
Study Java with Progate Note 1
Compare Java 8 Optional with Swift
HTML parsing with JAVA (scraping)
Run Java VM with WebAssembly
Screen transition with swing, java
Java unit tests with Mockito
[Java] Change the process according to the situation with the Strategy pattern
[Java 8] Duplicate deletion (& duplicate check) with Stream
Create an immutable class with JAVA
Java lambda expressions learned with Comparator
[Java, Scala] Image resizing with ImageIO
Build a Java project with Gradle
Install java with Ubuntu 16.04 based Docker
Java to learn with ramen [Part 1]