Who wants to earn more java insipred VV's?
Posted: December 13, 2004, 11:05 pm
Ok, here's the deal. For my final project, my professor tosses out a list of things that I, sadly, was busy running a 102degree fever and missed, and he won't answer any questions. Even better, when running the examples he mailed to the class, they don't work... which doesn't surprise me that much.
Here's the code for the examples, then I'll ask the questions.
Ok, now for the questions.
I'm supposed to read in a file into something like the above two examples and then print them. I'm ok on printing, that shouldn't be too hard. But there's a few things I don't understand and that the books don't explain.
What is the this. tag and what does it do?
What does it mean to have something "protected"?
How does it read in the information in the subclass that gets imported into the main class?
If someone could offer even a cusory explination on this, I'll donate VV's. If someone can get this example working so I can better undstand it, or even just document it out, I'll donate VV's. If anyone can offer a clear and concise deffinition, I'll donate a lot of VV's.
Here's the code for the examples, then I'll ask the questions.
Code: Select all
public class PhoneRecord
{
protected String Name, Phone;
public PhoneRecord(String Name, String Phone)
{
this.Name = Name;
this.Phone = Phone;
}
public void setName(String NewName)
{
Name = NewName;
}
public void setPhone(String NewPhone)
{
Phone = NewPhone;
}
public String getName()
{
return Name;
}
public String getPhone()
{
return Phone;
}
}
Code: Select all
// The "PhoneBook" class.
import java.awt.*;
import hsa.Console;
import PhoneRecord;
public class PhoneBook
{
static Console c; // The output console
public static void main (String[] args)
{
c = new Console ();
PhoneRecord person1 = new PhoneRecord("Andrew","304-424-3434");
PhoneRecord person2 = new PhoneRecord("Mike","304-863-5534");
// c.println(person1.Name + " " + person1.Phone);
// c.println(person2.getName() + " " + person2.getPhone());
PhoneRecord TheClass[] = new PhoneRecord[10];
// TheClass[0] = new PhoneRecord("Andrew","304-424-3434");
// TheClass[1] = new PhoneRecord("Mike","304-863-5534");
TheClass[2] = new PhoneRecord("Eric","304-275-1234");
TheClass[3] = new PhoneRecord("Jenny","304-3l4-4454");
c.println(TheClass[2].getName() + " " + TheClass[2].getPhone());
c.println(TheClass[3].getName() + " " + TheClass[3].getPhone());
c.println("\n\n\n\nLet's swap them\n\n\n\n\n");
Swap(TheClass,2,3);
c.println(TheClass[2].getName() + " " + TheClass[2].getPhone());
c.println(TheClass[3].getName() + " " + TheClass[3].getPhone());
Swap(TheClass,2,3);
c.println("\n\n\n\n\n\n");
c.println(TheClass[2].getName() + " " + TheClass[2].getPhone());
c.println(TheClass[3].getName() + " " + TheClass[3].getPhone());
} // main method
public static void Swap(PhoneRecord List[], int i, int j)
{
PhoneRecord Temp = List[i];
List[i] = List[j];
List[j] = Temp;
}
} // PhoneBook class
I'm supposed to read in a file into something like the above two examples and then print them. I'm ok on printing, that shouldn't be too hard. But there's a few things I don't understand and that the books don't explain.
What is the this. tag and what does it do?
What does it mean to have something "protected"?
How does it read in the information in the subclass that gets imported into the main class?
If someone could offer even a cusory explination on this, I'll donate VV's. If someone can get this example working so I can better undstand it, or even just document it out, I'll donate VV's. If anyone can offer a clear and concise deffinition, I'll donate a lot of VV's.