The beginning Java concepts are just starting to sink in with me, but I've been stuck on the same step of this exercise for several days now. I was hoping someone could point me in the right direction.
Description:
Create a class named TVProgram that has a field to store the name, the time and day of the program, the program information, cost, and whether it is a repeat or not.
That part is working as I can get the desired results.
The next step is to create a fourth program that uses the attributes from one of the three objects. This is what I cannot wrap my head around right now; how to reach in and get attributes from one of these objects.
Here is what I have so far:
CODE
package one;
/**
* Created by
* October 6, 2008
*
*
*/
public class Main {
public static void main(String [] args){
// Declare programs
TVprogram TVprogram1 = new TVprogram("Magnum PI", 21, "Monday",
"Private detective", true, 1000.0f);
TVprogram TVprogram2 = new TVprogram("Lost", 19, "Wednesday",
"Plane crash survivors", false, 200000.0f);
TVprogram TVprogram3 = new TVprogram("Today", 7, "Thursday",
"News", false, 10000.0f);
//TVprogram TVprogram4 = new TVprogram(???);
// Print the information using the toString method.
System.out.println("Program 1 data: " + TVprogram1.toString());
System.out.println();
System.out.println("Program 2 data: " + TVprogram2.toString());
System.out.println();
System.out.println("Program 3 data: " + TVprogram3.toString());
System.out.println();
// System.out.println("Program 4 data: " + TVprogram4.toString());
// System.out.println();
System.out.println(TVprogram1.toString());
System.out.println();
System.out.println(TVprogram2.toString());
System.out.println();
System.out.println(TVprogram3.toString());
System.out.println();
}
}
CODE
package one;
/**
*
* Created by
* October 6, 2008
*
*/
public class TVprogram {
//the attributes of program
private String name, pname;
private int time;
private String day, info;
private boolean repeat;
private float cost;
//constructor
public TVprogram(String programName,
int programTime,
String programDay,
String programInfo,
boolean programRepeat,
float programCost) {
name = programName;
time = programTime;
day = programDay;
info = programInfo;
repeat = programRepeat;
cost = programCost;
}
public String getName() {
return name;
}
public int getTime() {
return time;
}
public String getDay() {
return day;
}
public String getInfo() {
return info;
}
public boolean getRepeat() {
return repeat;
}
public float getCost() {
return cost;
}
public String getPname() {
return this.pname;
}
// Creating set methods
public void setProgramName(String givenName) {
name = givenName;
}
public void setProgramInfo(String givenInfo) {
info = givenInfo;
}
// Creating toString method
public String toString() {
return name + "\t" + info
+ "\nWhen: " + day + "\t" + time
+ "\nRepeat: " + repeat
+ "\nCost: " + cost;
}
}
Any help would be much appreciated. I have spent hours Googling and going through books and cannot figure out what concept I am missing.