Create a class named TVShow.java. Data Fields can include a String containing th
ID: 3626473 • Letter: C
Question
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.When I compile the UseTVShow file i get an
UseTvShow.java:28: cannot find symbol
symbol : constructor TvShow(java.lang.String,java.lang.String,int)
location: class TvShow
someShow[x] = new TvShow(name, day, channel);
here is my code:
import javax.swing.*;
public class UseTvShow
{
public static void main(String[] args)
{
String name;
String day;
String schannel;
int channel;
//changed to 2 to make it easier to test
TvShow[] someShow = new TvShow[2];
int x = 1;
for(x = 0; x < someShow.length; ++x)
{
name = JOptionPane.showInputDialog(null, "Enter Show Name " + (x+1));
day = JOptionPane.showInputDialog(null, "Enter Show Day " + (x+1));
schannel = JOptionPane.showInputDialog(null, "Enter Show Channel " + (x+1));
channel = Integer.parseInt(schannel);
//this only complies with no parameters, but produces null. I get "cannot find symbol" error. I cant figure out why.
someShow[x] = new TvShow(name, day, channel);
}
for(x = 0; x < someShow.length; ++x)
JOptionPane.showMessageDialog(null, "Show Name: " + someShow[x].getShowName() + " Show Day: " + someShow[x].getShowDay() +
" Show Channel: " + someShow[x].getShowChannel());
}
}
public class TvShow
{
private String showName;
private String showDay;
private int showChannel;
public void TvShow(String name, String day, int channel)
{
showName = name;
showDay = day;
showChannel = channel;
}
public String getShowName()
{
return showName;
}
public String getShowDay()
{
return showDay;
}
public int getShowChannel()
{
return showChannel;
}
public void setShowName(String sName)
{
showName = sName;
}
public void setShowDay(String dName)
{
showDay = dName;
}
public void setShowChannel(int chNum)
{
showChannel = chNum;
}
}
Thanks!
Explanation / Answer
1. import java.util.*; 2. import javax.swing.*; 3. public class TVShow 4. { 5. 6. //contructor that requires values for all of the data fields 7. public showListing(String name, String day, int channel) 8. { 9. showName = name; 10. showDay = day; 11. showChannel = channel; 12. } 13. 14. private String showName = “”; 15. private String showDay = “”; 16. private int showChannel = 0; 17. 18. //get methods 19. public String getShowName() 20. { 21. return showName; 22. } 23. public String getDay() 24. { 25. return showDay; 26. } 27. public int getChannel() 28. { 29. return showChannel; 30. } 31. 32. //set methods 33. public void setShowName(String nameOfShow) 34. { 35. showName = nameOfShow; 36. } 37. public void setDay(String dayOfWeek) 38. { 39. showDay = dayOfWeek; 40. } 41. public void setChannel(int myChannel) 42. { 43. showChannel = myChannel; 44. } 45. 46. 47. //display's the show name, day, and channel. 48. public void display(String name, String day, int channel) 49. { 50. showName = name; 51. showDay = day; 52. showChannel = channel; 53. System.out.println(showName + " airs on " + showDay + ", on channel " + 54. showChannel + "."); 55. } 56. } 1. import java.util.*; 2. import javax.swing.*; 3. public class UseTVShow 4. { 5. public static void main(String[] args) 6. { 7. //instantiate a new array with 5 elements. 8. //TVShow[] show = new TVShow[5]; 9. String[] show = new String[5]; 10. int highestSub = show.length - 1; 11. int x = 0; 12. 13. String showString = ""; 14. 15. show[x] = JOptionPane.showInputDialog(null, 16. "Enter a list of up to 5 TV shows, or xxx to quit:"); 17. while(!show[x].equals("xxx") && xRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.