Prerequisite: Sextet Class, Quintet Class
Below are the methods to implement a Sextet Class using Quintet Class in Java:
- Using direct values
// 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);
}
}
Output:
Quintet: [Quintet, Quartet, Triplet, Pair, Unit] Sextet: [Sextet, Quintet, Quartet, Triplet, Pair, Unit]
- Using Quintet.add() method
// 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);
}
}
Output:
Quintet: [Quintet, Quartet, Triplet, Pair, Unit] Sextet: [Quintet, Quartet, Triplet, Pair, Unit, Sextet]
- Using Quintet.addAtX() method
Program 1: Adding at Position 0 using 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);
}
}
Output:
Quintet: [Quintet, Quartet, Triplet, Pair, Unit] Sextet: [Sextet, Quintet, Quartet, Triplet, Pair, Unit]
Program 2: Adding at Position 1 using 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);
}
}
Output:
Quintet: [Quintet, Quartet, Triplet, Pair, Unit] Sextet: [Quintet, Sextet, 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 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);
}
}
Output:
Quintet: [Quintet, Quartet, Triplet, Pair, Unit] Sextet: [Quintet, Quartet, Sextet, 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 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);
}
}
Output:
Quintet: [Quintet, Quartet, Triplet, Pair, Unit] Sextet: [Quintet, Quartet, Triplet, Sextet, 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 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);
}
}
Output:
Quintet: [Quintet, Quartet, Triplet, Pair, Unit] Sextet: [Quintet, Quartet, Triplet, Pair, Sextet, 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 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);
}
}
Output:
Quintet: [Quintet, Quartet, Triplet, Pair, Unit] Sextet: [Quintet, Quartet, Triplet, Pair, Unit, Sextet]