Implemente la clase Octet de la clase Septet en Java usando JavaTuples

Prerrequisito: Clase de Octeto, Clase de Septeto

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

  1. Usando valores directos

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

    Producción:

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

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

    Producción:

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

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

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

    Producción:

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

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

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

    Producción:

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

    Producción:

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

    Producción:

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

    Producción:

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

    Producción:

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

    Producción:

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

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

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

    Producción:

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

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 *