Related Articles

Related Articles

Implement Sextet Class from Quintet Class in Java using JavaTuples
  • Last Updated : 24 Sep, 2018

Prerequisite: Sextet Class, Quintet Class

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

  1. Using direct values
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // 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);
        }
    }

    chevron_right

    
    

    Output:

    Quintet: [Quintet, Quartet, Triplet, Pair, Unit]
    Sextet: [Sextet, Quintet, Quartet, Triplet, Pair, Unit]
  2. Using Quintet.add() method
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // 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);
        }
    }

    chevron_right

    
    

    Output:

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

    Program 1: Adding at Position 0 using addAt0()



    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // 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);
        }
    }

    chevron_right

    
    

    Output:

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

    Program 2: Adding at Position 1 using addAt1()

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // 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);
        }
    }

    chevron_right

    
    

    Output:

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

    Program 3: Adding at Position 2 using addAt2()

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // 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);
        }
    }

    chevron_right

    
    

    Output:

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

    Program 4: Adding at Position 3 using addAt3()

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // 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);
        }
    }

    chevron_right

    
    

    Output:

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

    Program 5: Adding at Position 4 using addAt4()

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // 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);
        }
    }

    chevron_right

    
    

    Output:

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

    Program 6: Adding at Position 5 using addAt5()

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // 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);
        }
    }

    chevron_right

    
    

    Output:

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

    Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.




    My Personal Notes arrow_drop_up
Recommended Articles
Page :