📜  使用 JavaTuples 在Java中从 Ennead 类实现 Decade 类

📅  最后修改于: 2022-05-13 01:54:20.933000             🧑  作者: Mango

使用 JavaTuples 在Java中从 Ennead 类实现 Decade 类

先决条件: Decade Class,Ennead Class

以下是在Java中使用 Ennead 类实现 Decade 类的方法:

  1. 使用直接值
    // Java program to illustrate
    // implementing Decade Class 
    // from Ennead Class 
    // using direct values
      
    import java.util.*;
    import org.javatuples.*;
      
    class GfG {
      
        public static void main(String[] args)
        {
            // Create Ennead
            Ennead
                ennead = new Ennead(
                    "Ennead", "Octet", "Septet", "Sextet", "Quintet", "Quartet", "Triplet", "Pair", "Unit");
      
            // Print the Ennead
            System.out.println("Ennead: " + ennead);
      
            // Create Decade from Ennead
            Decade
                decade = new Decade(
                    "Decade",
                    ennead.getValue0(),
                    ennead.getValue1(),
                    ennead.getValue2(),
                    ennead.getValue3(),
                    ennead.getValue4(),
                    ennead.getValue5(),
                    ennead.getValue6(),
                    ennead.getValue7(),
                    ennead.getValue8());
      
            // Print the Decade
            System.out.println("Decade: " + decade);
        }
    }
    

    输出:

    Ennead: [Ennead, Octet, Septet, Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    Decade: [Decade, Ennead, Octet, Septet, Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    
  2. 使用 Ennead.add() 方法
    // Java program to illustrate
    // implementing Decade Class 
    // from Ennead Class 
    // using add() values
      
    import java.util.*;
    import org.javatuples.*;
      
    class GfG {
        public static void main(String[] args)
        {
            // Create Ennead
            Ennead
                ennead = new Ennead(
                    "Ennead", "Octet", "Septet", "Sextet", "Quintet", "Quartet", "Triplet", "Pair", "Unit");
      
            // Print the Ennead
            System.out.println("Ennead: " + ennead);
      
            // Create Decade from Ennead
            Decade
                decade = ennead.add("Decade");
      
            // Print the Decade
            System.out.println("Decade: " + decade);
        }
    }
    

    输出:

    Ennead: [Ennead, Octet, Septet, Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    Decade: [Ennead, Octet, Septet, Sextet, Quintet, Quartet, Triplet, Pair, Unit, Decade]
    
  3. 使用 Ennead.addAtX() 方法

    程序 1:使用 addAt0() 在位置 0 添加

    // Java program to illustrate
    // implementing Decade Class 
    // from Ennead Class 
    // using addAt0() values
      
    import java.util.*;
    import org.javatuples.*
      
        class GfG {
        public static void main(String[] args)
        {
           // Create Ennead
            Ennead
                ennead = new Ennead(
                    "Ennead", "Octet", "Septet", "Sextet", "Quintet", "Quartet", "Triplet", "Pair", "Unit");
      
            // Print the Ennead
            System.out.println("Ennead: " + ennead);
      
            // Create Decade from Ennead
            Decade
                decade = ennead.addAt0("Decade");
      
            // Print the Decade
            System.out.println("Decade: " + decade);
        }
    }
    

    输出:

    Ennead: [Ennead, Octet, Septet, Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    Decade: [Decade, Ennead, Octet, Septet, Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    

    程序 2:使用 addAt1() 在位置 1 添加

    // Java program to illustrate
    // implementing Decade Class 
    // from Ennead Class 
    // using add()At1
      
    import java.util.*;
    import org.javatuples.*;
      
    class GfG {
        public static void main(String[] args)
        {
            // Create Ennead
            Ennead
                ennead = new Ennead(
                    "Ennead", "Octet", "Septet", "Sextet", "Quintet", "Quartet", "Triplet", "Pair", "Unit");
      
            // Print the Ennead
            System.out.println("Ennead: " + ennead);
      
            // Create Decade from Ennead
            Decade
                decade = ennead.addAt1("Decade");
      
            // Print the Decade
            System.out.println("Decade: " + decade);
        }
    }
    

    输出:

    Ennead: [Ennead, Octet, Septet, Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    Decade: [Ennead, Decade, Octet, Septet, Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    

    程序 3:使用 addAt2() 在位置 2 添加

    // Below is a Java program to demonstrate
    // use of addAt2() method with
    // direct value
      
    import java.util.*;
    import org.javatuples.*
      
        class GfG {
        public static void main(String[] args)
        {
            // Create Ennead
            Ennead
                ennead = new Ennead(
                    "Ennead", "Octet", "Septet", "Sextet", "Quintet", "Quartet", "Triplet", "Pair", "Unit");
      
            // Print the Ennead
            System.out.println("Ennead: " + ennead);
      
            // Create Decade from Ennead
            Decade
                decade = ennead.addAt2("Decade");
      
            // Print the Decade
            System.out.println("Decade: " + decade);
        }
    }
    

    输出:

    Ennead: [Ennead, Octet, Septet, Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    Decade: [Ennead, Octet, Decade, Septet, Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    

    程序 4:使用 addAt3() 在位置 3 添加

    // Below is a Java program to demonstrate
    // use of addAt3() method with
    // direct value
      
    import java.util.*;
    import org.javatuples.*
      
        class GfG {
        public static void main(String[] args)
        {
            // Create Ennead
            Ennead
                ennead = new Ennead(
                    "Ennead", "Octet", "Septet", "Sextet", "Quintet", "Quartet", "Triplet", "Pair", "Unit");
      
            // Print the Ennead
            System.out.println("Ennead: " + ennead);
      
            // Create Decade from Ennead
            Decade
                decade = ennead.addAt3("Decade");
      
            // Print the Decade
            System.out.println("Decade: " + decade);
        }
    }
    

    输出:

    Ennead: [Ennead, Octet, Septet, Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    Decade: [Ennead, Octet, Septet, Decade, Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    

    程序 5:使用 addAt4() 在位置 4 添加

    // Below is a Java program to demonstrate
    // use of addAt4() method with
    // direct value
      
    import java.util.*;
    import org.javatuples.*
      
       class GfG {
        public static void main(String[] args)
        {
            // Create Ennead
            Ennead
                ennead = new Ennead(
                    "Ennead", "Octet", "Septet", "Sextet", "Quintet", "Quartet", "Triplet", "Pair", "Unit");
      
            // Print the Ennead
            System.out.println("Ennead: " + ennead);
      
            // Create Decade from Ennead
            Decade
                decade = ennead.addAt4("Decade");
      
            // Print the Decade
            System.out.println("Decade: " + decade);
        }
    }
    

    输出:

    Ennead: [Ennead, Octet, Septet, Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    Decade: [Ennead, Octet, Septet, Sextet, Decade, Quintet, Quartet, Triplet, Pair, Unit]
    

    程序 6:使用 addAt5() 在位置 5 添加

    // Below is a Java program to demonstrate
    // use of addAt5() method with
    // direct value
      
    import java.util.*;
    import org.javatuples.*
      
        class GfG {
        public static void main(String[] args)
        {
            // Create Ennead
            Ennead
                ennead = new Ennead(
                    "Ennead", "Octet", "Septet", "Sextet", "Quintet", "Quartet", "Triplet", "Pair", "Unit");
      
            // Print the Ennead
            System.out.println("Ennead: " + ennead);
      
            // Create Decade from Ennead
            Decade
                decade = ennead.addAt5("Decade");
      
            // Print the Decade
            System.out.println("Decade: " + decade);
        }
    }
    

    输出:

    Ennead: [Ennead, Octet, Septet, Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    Decade: [Ennead, Octet, Septet, Sextet, Quintet, Decade, Quartet, Triplet, Pair, Unit]
    

    程序 7:使用 addAt6() 在位置 6 添加

    // Below is a Java program to demonstrate
    // use of addAt6() method with
    // direct value
      
    import java.util.*;
    import org.javatuples.*
      
       class GfG {
        public static void main(String[] args)
        {
            // Create Ennead
            Ennead
                ennead = new Ennead(
                    "Ennead", "Octet", "Septet", "Sextet", "Quintet", "Quartet", "Triplet", "Pair", "Unit");
      
            // Print the Ennead
            System.out.println("Ennead: " + ennead);
      
            // Create Decade from Ennead
            Decade
                decade = ennead.addAt6("Decade");
      
            // Print the Decade
            System.out.println("Decade: " + decade);
        }
    }
    

    输出:

    Ennead: [Ennead, Octet, Septet, Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    Decade: [Ennead, Octet, Septet, Sextet, Quintet, Quartet, Decade, Triplet, Pair, Unit]
    

    程序 8:使用 addAt7() 在位置 7 添加

    // Below is a Java program to demonstrate
    // use of addAt7() method with
    // direct value
      
    import java.util.*;
    import org.javatuples.*
      
       class GfG {
        public static void main(String[] args)
        {
            // Create Ennead
            Ennead
                ennead = new Ennead(
                    "Ennead", "Octet", "Septet", "Sextet", "Quintet", "Quartet", "Triplet", "Pair", "Unit");
      
            // Print the Ennead
            System.out.println("Ennead: " + ennead);
      
            // Create Decade from Ennead
            Decade
                decade = ennead.addAt7("Decade");
      
            // Print the Decade
            System.out.println("Decade: " + decade);
        }
    }
    

    输出:

    Ennead: [Ennead, Octet, Septet, Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    Decade: [Ennead, Octet, Septet, Sextet, Quintet, Quartet, Triplet, Decade, Pair, Unit]
    

    程序 9:使用 addAt8() 在位置 8 添加

    // Below is a Java program to demonstrate
    // use of addAt8() method with
    // direct value
      
    import java.util.*;
    import org.javatuples.*
      
       class GfG {
        public static void main(String[] args)
        {
            // Create Ennead
            Ennead
                ennead = new Ennead(
                    "Ennead", "Octet", "Septet", "Sextet", "Quintet", "Quartet", "Triplet", "Pair", "Unit");
      
            // Print the Ennead
            System.out.println("Ennead: " + ennead);
      
            // Create Decade from Ennead
            Decade
                decade = ennead.addAt8("Decade");
      
            // Print the Decade
            System.out.println("Decade: " + decade);
        }
    }
    

    输出:

    Ennead: [Ennead, Octet, Septet, Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    Decade: [Ennead, Octet, Septet, Sextet, Quintet, Quartet, Triplet, Pair, Decade, Unit]
    

    程序 10:使用 addAt9() 在位置 9 添加

    // Below is a Java program to demonstrate
    // use of addAt9() method with
    // direct value
      
    import java.util.*;
    import org.javatuples.*
      
       class GfG {
        public static void main(String[] args)
        {
            // Create Ennead
            Ennead
                ennead = new Ennead(
                    "Ennead", "Octet", "Septet", "Sextet", "Quintet", "Quartet", "Triplet", "Pair", "Unit");
      
            // Print the Ennead
            System.out.println("Ennead: " + ennead);
      
            // Create Decade from Ennead
            Decade
                decade = ennead.addAt9("Decade");
      
            // Print the Decade
            System.out.println("Decade: " + decade);
        }
    }
    

    输出:

    Ennead: [Ennead, Octet, Septet, Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    Decade: [Ennead, Octet, Septet, Sextet, Quintet, Quartet, Triplet, Pair, Unit, Decade]