Implemente Sextet Class de Quintet Class en Java usando JavaTuples

Prerrequisito: Clase de Sexteto, Clase de Quinteto

A continuación se muestran los métodos para implementar una clase de sexteto utilizando la clase de quinteto en Java:

  1. Usando valores directos

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

    Producción:

    Quintet: [Quintet, Quartet, Triplet, Pair, Unit]
    Sextet: [Sextet, Quintet, Quartet, Triplet, Pair, Unit]
  2. Usando el método Quintet.add()

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

    Producción:

    Quintet: [Quintet, Quartet, Triplet, Pair, Unit]
    Sextet: [Quintet, Quartet, Triplet, Pair, Unit, Sextet]
  3. Usando el método Quintet.addAtX()

    Programa 1: Agregar en la Posición 0 usando addAt0()

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

    Producción:

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

    Programa 2: Agregar en la Posición 1 usando addAt1()

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

    Producción:

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

    Programa 3: Agregar en la Posición 2 usando addAt2()

    // 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 Quintet
            Quintet<String, String, String, String, String>
                quintet = new Quintet<String, String, String, String, String>(
                    "Quintet", "Quartet", "Triplet", "Pair", "Unit");
      
            // Print the Quintet
            System.out.println("Quintet: " + quintet);
      
            // Using add() to create Sextet
            Sextet<String, String, String, String, String, String>
                sextet = quintet.addAt2("Sextet");
      
            // Print the Sextet
            System.out.println("Sextet: " + sextet);
        }
    }

    Producción:

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

    Programa 4: Agregar en la Posición 3 usando addAt3()

    // 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 Quintet
            Quintet<String, String, String, String, String>
                quintet = new Quintet<String, String, String, String, String>(
                    "Quintet", "Quartet", "Triplet", "Pair", "Unit");
      
            // Print the Quintet
            System.out.println("Quintet: " + quintet);
      
            // Using add() to create Sextet
            Sextet<String, String, String, String, String, String>
                sextet = quintet.addAt3("Sextet");
      
            // Print the Sextet
            System.out.println("Sextet: " + sextet);
        }
    }

    Producción:

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

    Programa 5: Agregar en la Posición 4 usando addAt4()

    // 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 Quintet
            Quintet<String, String, String, String, String>
                quintet = new Quintet<String, String, String, String, String>(
                    "Quintet", "Quartet", "Triplet", "Pair", "Unit");
      
            // Print the Quintet
            System.out.println("Quintet: " + quintet);
      
            // Using add() to create Sextet
            Sextet<String, String, String, String, String, String>
                sextet = quintet.addAt4("Sextet");
      
            // Print the Sextet
            System.out.println("Sextet: " + sextet);
        }
    }

    Producción:

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

    Programa 6: Agregar en la Posición 5 usando addAt5()

    // 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 Quintet
            Quintet<String, String, String, String, String>
                quintet = new Quintet<String, String, String, String, String>(
                    "Quintet", "Quartet", "Triplet", "Pair", "Unit");
      
            // Print the Quintet
            System.out.println("Quintet: " + quintet);
      
            // Using add() to create Sextet
            Sextet<String, String, String, String, String, String>
                sextet = quintet.addAt5("Sextet");
      
            // Print the Sextet
            System.out.println("Sextet: " + sextet);
        }
    }

    Producción:

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

Publicación traducida automáticamente

Artículo escrito por Code_r y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *