Okay I am working on arrays in class this week and since it is an online course I don't have anyone to turn to. YAY me! Basically this is what I have been asked to do.
Create a class named TVShow.java. Data Fields can include a String containing the Name of the show, a String containing the day that the show is broadcast(i.e. “Monday”) and an integer for the channel where the show can be viewed. Methods will include a constructor that requires values for all of the data fields, plus methods to get, set and display the values of the data fields. Create a UseTVShow.java file that prompts the user to input up to 5 TV shows and stores the data in an array of objects first, then displays them as a list.
For the TVShow.java class I have this:
import javax.swing.*;
public class TVShow
{
private int tvChannel = 0;
private String showDay = "";
private String showName = "";
public TVShow(String name, String day, int channel)
{
showName = name;
showDay = day;
tvChannel = channel;
}
public void setTVChannel(int theChannel)
{
tvChannel = theChannel;
}
public int getTVChannel()
{
return tvChannel;
}
public void setDay(String weekDay)
{
showDay = weekDay;
}
public String getDay()
{
return showDay;
}
public void setShowName(String nameOfShow)
{
showName = nameOfShow;
}
public String getShowName()
{
return showName;
}
public void setDisplay()
{
JOptionPane.showMessageDialog(null, showName + " is on " + showDay + "'s, "
+ "on channel " + tvChannel);
}
}
For the Main method in the useTVShow.java I have this:
import javax.swing.*;
import java.util.*;
public class UseTVShow
{
public static void main(String[] args)
{
final int TV_MAX = 5;
TVShow[] myShowArray = new TVShow[TV_MAX];
String tvInput = JOptionPane.showInputDialog(null, "Please enter a television show: ");
for(int d = 0; d < TV_MAX; ++d)
myShowArray[d].setShowName(tvInput);
for(int d = 0; d < TV_MAX; ++d)
myShowArray[d].setDay("Monday");
for(int d = 0; d < TV_MAX; ++d)
myShowArray[d].setTVChannel(1 + d);
for(int d = 0; d < TV_MAX; ++d)
JOptionPane.showMessageDialog(null, "Show: " + d + " " + myShowArray[d].getShowName()
+ " airs on " + myShowArray[d].getDay() + "'s on channel "
+ myShowArray[d].getTVChannel());
}
}
I am having two issues here, first: I am unable to enter more than 1 television show. Second: I am unable to display what I have entered or even the other variables from the get and set methods. HELP!