Question
Java - need help getting started. This program tracks the members of a cast on a TV show. Instructions: Create a class called CastList with
Java - need help getting started.
This program tracks the members of a cast on a TV show.
Instructions:
Create a class called CastList with these data members:
A private array of up to 5 Role objects
any other data members you may need
And these methods:
a method to add a Role object
a method to delete a Role object
a toString method that will print out the number of roles and the details of each role including the actors name and the characters name
In the main method of the Cast class, create a CastList object and add the roles we have have been using to this CastList object and print the entire CastList object.
---Actor.java----
package lesson2_3;
public class Actor {
private String name;
public Actor( String n){
name = n;
}
@Override
public String toString() {
return "Actor [name=" + name + "]";
}
}
---Cast.java---
package lesson2_3;
import java.io.PrintStream;
public class Cast {
static PrintStream syso = System.out;
public static void main(String[] args) {
int seasonf = 1;
Role r1 = new Role("Leslie Knope", "Amy Poehler", seasonf);
Role r2 = new Role("Ron Swanson", "Nick Offerman", seasonf);
int season2 = 2;
Role r3 = new Role("Ben Wyatt", "Adam Scott", season2);
syso.println(r1);
syso.println(r2);
syso.println(r3);
}
}
---Role.java---
package lesson2_3;
public class Role {
private String name;
private Actor actor;
private int startseason;
public Role( String n, String a, int start){
name = n;
actor = new Actor( a );
startseason = start;
}
@Override
public String toString() {
return "Role [name=" + name + ", " + startseason + " " + actor + "]";
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started