Tutorialspoint.dev

Implement Septet Class from Sextet Class in Java using JavaTuples

Prerequisite: Septet Class, Sextet Class

Below are the methods to implement a Septet Class using Sextet Class in Java:

  1. Using direct values
    // 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);
        }
    }

    Output:

    Sextet: [Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    Septet: [Septet, Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    
  2. Using Sextet.add() method
    // Java program to illustrate
    // implementing Septet Class
    // from Sextet Class
    // using 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);
        }
    }

    Output:



    Sextet: [Sextet, Quintet, Quartet, Triplet, Pair, Unit]
    Septet: [Sextet, Quintet, Quartet, Triplet, Pair, Unit, Septet]
    
  3. Using Sextet.addAtX() method

    Program 1: Adding at Position 0 using 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);
        }
    }

    Output:

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

    Program 2: Adding at Position 1 using 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);
        }
    }

    Output:

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

    Program 3: Adding at Position 2 using 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);
        }
    }

    Output:

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

    Program 4: Adding at Position 3 using 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);
        }
    }

    Output:

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

    Program 5: Adding at Position 4 using 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);
        }
    }

    Output:

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

    Program 6: Adding at Position 5 using 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);
        }
    }

    Output:

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

    Program 7: Adding at Position 6 using 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);
        }
    }

    Output:

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


This article is attributed to GeeksforGeeks.org

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter