Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a class named TVShow.java. Data Fields can include a String containing th

ID: 3630057 • 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.

Explanation / Answer

// Create a class named TVShow.java.
public class TVShow
{
// 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.
private String name, day;
private int channel;

// 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.
public TVShow(String n, String d, int c)
{
name = n;
day = d;
channel = c;
}

public void setName(String n)
{
name = n;
}

public void setDay(String d)
{
day = d;
}

public void setChannel(int c)
{
channel = c;
}

public String getName()
{
return name;
}

public String getDay()
{
return day;
}

public int getChannel()
{
return channel;
}

public String toString()
{
return name+" on "+day+" on channel "+channel;
}
}

// Create a UseTVShow.java file
import java.util.*;

public class UseTVShow
{
// 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.
public static void main(String[] args)
{
Scanner kb = new Scanner(System.in);

System.out.print("How many TV shows? ");
TVShow[] shows = new TVShow[kb.nextInt()];

for(int i = 0; i < shows.length; i++)
{
System.out.print("Name of show? ");
String name = kb.nextLine();
System.out.print("Day of show? ");
String day = kb.next();
System.out.print("Channel? ");
int channel =kb.nextInt();

shows[i] = new TVShow(name, day, channel);
}

System.out.println(Arrays.toString(shows));
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote