Implemente la clase de septeto de la clase de sexteto en Java usando JavaTuples

Prerrequisito: Clase de septeto , clase de sexteto

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

  1. Usando valores directos

    // 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<String, String, String, String, String, String>
                sextet = new Sextet<String, String, String, String, String, String>(
                    "Sextet", "Quintet", "Quartet", "Triplet", "Pair", "Unit");
      
            // Print the Sextet
            System.out.println("Sextet: " + sextet);
      
            // Create Septet from Sextet
            Septet<String, String, String, String, String, String, String>
                septet = new Septet<String, String, String, String, String, String, String>(
                    "Septet",
                    sextet.getValue0(),
                    sextet.getValue1(),
                    sextet.getValue2(),
                    sextet.getValue3(),
                    sextet.getValue4(),
                    sextet.getValue5());
      
            // Print the Septet
            System.out.println("Septet: " + septet);
        }
    }

    Producción:

    Sextet: [Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    Septet: [Septet, Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    
  2. Uso del método Sextet.add()
    // programa Java para ilustrar
    // la implementación de la clase Septet
    // desde la clase Sextet
    // usando add()

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

    Producción:

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

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

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

    Producción:

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

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

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

    Producción:

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

    Producción:

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

    Producción:

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

    Producción:

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

    Producción:

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

    Programa 7: Agregar en la Posición 6 usando addAt6()

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

    Producción:

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

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 *