I am new to java and I am trying to learn how to to reduce lines of code that are redundant in a simple file I made. I am trying to figure out how to reduce this code down to 13 methods not including the main and reduce any extra lines without using array's
[CODE=java]public class Song {
public static void main(String[] args) {
One();
Two();
Three();
Four();
Five();
Six();
Seven();
}
public static void One() {
System.out.prin tln("On the 1st day of \"Xmas\", my true love sent to me");
OneVerse();
}
public static void Two() {
System.out.prin tln("");
System.out.prin tln("On the 2nd day of \"Xmas\", my true love sent to me");
TwoVerse();
OneVerse();
}
public static void Three() {
System.out.prin tln("");
System.out.prin tln("On the 3rd day of \"Xmas\", my true love sent to me");
ThreeVerse();
TwoVerse();
OneVerse();
}
public static void Four() {
System.out.prin tln("");
System.out.prin tln("On the 4th day of \"Xmas\", my true love sent to me");
FourVerse();
ThreeVerse();
TwoVerse();
OneVerse();
}
public static void Five() {
System.out.prin tln("");
System.out.prin tln("On the 5th day of \"Xmas\", my true love sent to me");
FiveVerse();
FourVerse();
ThreeVerse();
TwoVerse();
OneVerse();
}
public static void Six() {
System.out.prin tln("");
System.out.prin tln("On the 6th day of \"Xmas\", my true love sent to me");
SixVerse();
FiveVerse();
FourVerse();
ThreeVerse();
TwoVerse();
OneVerse();
}
public static void Seven() {
System.out.prin tln("On the 7th day of \"Xmas\", my true love sent to me");
SevenVerse();
SixVerse();
FiveVerse();
FourVerse();
ThreeVerse();
TwoVerse();
OneVerse();
}
public static void OneVerse() {
System.out.prin tln("a partridge in a pear tree.");
}
public static void TwoVerse() {
System.out.prin tln("two turtle doves, and");
}
public static void ThreeVerse() {
System.out.prin tln("three French hens,");
}
public static void FourVerse() {
System.out.prin tln("four calling birds,");
}
public static void FiveVerse() {
System.out.prin tln("five golden rings,");
}
public static void SixVerse() {
System.out.prin tln("six geese a-laying,");
}
public static void SevenVerse() {
System.out.prin tln("Seven swans a-swimming,");
}
}[/CODE]
[CODE=java]public class Song {
public static void main(String[] args) {
One();
Two();
Three();
Four();
Five();
Six();
Seven();
}
public static void One() {
System.out.prin tln("On the 1st day of \"Xmas\", my true love sent to me");
OneVerse();
}
public static void Two() {
System.out.prin tln("");
System.out.prin tln("On the 2nd day of \"Xmas\", my true love sent to me");
TwoVerse();
OneVerse();
}
public static void Three() {
System.out.prin tln("");
System.out.prin tln("On the 3rd day of \"Xmas\", my true love sent to me");
ThreeVerse();
TwoVerse();
OneVerse();
}
public static void Four() {
System.out.prin tln("");
System.out.prin tln("On the 4th day of \"Xmas\", my true love sent to me");
FourVerse();
ThreeVerse();
TwoVerse();
OneVerse();
}
public static void Five() {
System.out.prin tln("");
System.out.prin tln("On the 5th day of \"Xmas\", my true love sent to me");
FiveVerse();
FourVerse();
ThreeVerse();
TwoVerse();
OneVerse();
}
public static void Six() {
System.out.prin tln("");
System.out.prin tln("On the 6th day of \"Xmas\", my true love sent to me");
SixVerse();
FiveVerse();
FourVerse();
ThreeVerse();
TwoVerse();
OneVerse();
}
public static void Seven() {
System.out.prin tln("On the 7th day of \"Xmas\", my true love sent to me");
SevenVerse();
SixVerse();
FiveVerse();
FourVerse();
ThreeVerse();
TwoVerse();
OneVerse();
}
public static void OneVerse() {
System.out.prin tln("a partridge in a pear tree.");
}
public static void TwoVerse() {
System.out.prin tln("two turtle doves, and");
}
public static void ThreeVerse() {
System.out.prin tln("three French hens,");
}
public static void FourVerse() {
System.out.prin tln("four calling birds,");
}
public static void FiveVerse() {
System.out.prin tln("five golden rings,");
}
public static void SixVerse() {
System.out.prin tln("six geese a-laying,");
}
public static void SevenVerse() {
System.out.prin tln("Seven swans a-swimming,");
}
}[/CODE]
Comment