📜  使用 JavaTuples 在Java中从 Sextet 类实现 Septet 类

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

使用 JavaTuples 在Java中从 Sextet 类实现 Septet 类

先决条件:七重奏班,六重奏班

以下是在Java中使用 Sextet Class 实现 Septet Class 的方法:

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

    输出:

    Sextet: [Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    Septet: [Septet, Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    
  2. 使用 Sextet.add() 方法
    // Java程序来说明
    // 实现 Septet 类
    // 来自六重奏类
    // 使用 add()
    import java.util.*;
    import org.javatuples.*;
      
    class GfG {
        public static void main(String[] args)
        {
            // Create Sextet
            Sextet
                sextet = new Sextet(
                    "Sextet", "Quintet", "Quartet", "Triplet", "Pair", "Unit");
      
            // Print the Sextet
            System.out.println("Sextet: " + sextet);
      
            // Create Septet from Sextet
            Septet
                septet = sextet.add("Septet");
      
            // Print the Septet
            System.out.println("Septet: " + septet);
        }
    }
    

    输出:

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

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

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

    输出:

    Sextet: [Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    Septet: [Septet, Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    

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

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

    输出:

    Sextet: [Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    Septet: [Sextet, Septet, 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 Sextet
            Sextet
                sextet = new Sextet(
                    "Sextet", "Quintet", "Quartet", "Triplet", "Pair", "Unit");
      
            // Print the Sextet
            System.out.println("Sextet: " + sextet);
      
            // Create Septet from Sextet
            Septet
                septet = sextet.addAt2("Septet");
      
            // Print the Septet
            System.out.println("Septet: " + septet);
        }
    }
    

    输出:

    Sextet: [Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    Septet: [Sextet, Quintet, Septet, 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 Sextet
            Sextet
                sextet = new Sextet(
                    "Sextet", "Quintet", "Quartet", "Triplet", "Pair", "Unit");
      
            // Print the Sextet
            System.out.println("Sextet: " + sextet);
      
            // Create Septet from Sextet
            Septet
                septet = sextet.addAt3("Septet");
      
            // Print the Septet
            System.out.println("Septet: " + septet);
        }
    }
    

    输出:

    Sextet: [Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    Septet: [Sextet, Quintet, Quartet, Septet, 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 Sextet
            Sextet
                sextet = new Sextet(
                    "Sextet", "Quintet", "Quartet", "Triplet", "Pair", "Unit");
      
            // Print the Sextet
            System.out.println("Sextet: " + sextet);
      
            // Create Septet from Sextet
            Septet
                septet = sextet.addAt4("Septet");
      
            // Print the Septet
            System.out.println("Septet: " + septet);
        }
    }
    

    输出:

    Sextet: [Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    Septet: [Sextet, Quintet, Quartet, Triplet, Septet, 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 Sextet
            Sextet
                sextet = new Sextet(
                    "Sextet", "Quintet", "Quartet", "Triplet", "Pair", "Unit");
      
            // Print the Sextet
            System.out.println("Sextet: " + sextet);
      
            // Create Septet from Sextet
            Septet
                septet = sextet.addAt5("Septet");
      
            // Print the Septet
            System.out.println("Septet: " + septet);
        }
    }
    

    输出:

    Sextet: [Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    Septet: [Sextet, Quintet, Quartet, Triplet, Pair, Septet, 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 Sextet
            Sextet
                sextet = new Sextet(
                    "Sextet", "Quintet", "Quartet", "Triplet", "Pair", "Unit");
      
            // Print the Sextet
            System.out.println("Sextet: " + sextet);
      
            // Create Septet from Sextet
            Septet
                septet = sextet.addAt6("Septet");
      
            // Print the Septet
            System.out.println("Septet: " + septet);
        }
    }
    

    输出:

    Sextet: [Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    Septet: [Sextet, Quintet, Quartet, Triplet, Pair, Unit, Septet]