Okay so I have an array of Objects.. My goal is to get the output to print every "Song" the user inputs
But for some reason only the last song in the array is printing which is confusing me
import java.util.*;
import java.util.Arrays;
public class SongRunner1
{
public static void main(String[] args){
String title;
String t;
String artist;
String a;
int time;
int tt;
int rating;
int rr;
double totalsum = 0;
int sum = 0;
Random r = new Random();
Scanner console = new Scanner(System.in);
System.out.println("Welcome to your music storing program!");
System.out.println("How many songs will be inputted?");
int number = console.nextInt();
Songs[] IT = new Songs[number];
for(int i = 1; i <= number; i = i + 1){
if(i <= number){
System.out.println("\nThis is song #" + i);
String s = console.nextLine();
System.out.println("What is this songs name?");
title = console.nextLine();
System.out.println("Who is the artist of this song?");
artist = console.nextLine();
a = artist;
System.out.println("How long is this song in seconds?");
time = console.nextInt();
tt = time;
if(time <= 0){
System.out.println("Invalid command!");
System.out.println("how long is this song in seconds?");
time = console.nextInt();
time++;
}
sum += time;
rating = r.nextInt(5)+ 1;
rr = rating;
totalsum += rating;
Songs Song1 = new Songs(title, artist, time, rating);
if(i >= number){
System.out.println("=======Song Library Summary=======");
System.out.println("Title \t \t Artist \t \t Time \t \t");
for(int b = 0; b < IT.length;b++){
//System.out.println(Arrays.toString(IT));
String temp = Song1.toString();
System.out.println(Song1);
}
System.out.println("\n \n" + "The average rating is:"+ (totalsum)/(double)(number));
System.out.println("The total time is:"+ sum/60 + ":" + sum%60+ "\n");
}
}
}
}
}
OUTPUT:
Welcome to your music storing program!
How many songs will be inputted?
2
This is song #1
What is this songs name?
Hot N Cold
Who is the artist of this song?
Katy PErry
How long is this song in seconds?
300
This is song #2
What is this songs name?
Ghost
Who is the artist of this song?
Kid Cudi
How long is this song in seconds?
250
=======Song Library Summary=======
Title Artist Time
Ghost Kid Cudi 4:10 1
Ghost Kid Cudi 4:10 1
The average rating is:3.5
The total time is:9:10
----------------------------------------------------------------
So for some reason only the last object of Type Songs is printing. Any help would be tremendously appreciated, I got the code to print the array but only the last one prints I've tried with 4+ diff songs and no matter what only the last one prints...