Hello world, I'm new to the community. I am a beginning programmer of java(well so far) and I got this programming class. I am seeking ideas and help.
Okay, I got this assignment. I need to make a contact list that has an output like this:
What I want is a column for Name, City, Home, Cell, and Type. And instead of using the \t to tab it to the right place. Here's the code I have which has 2 class:
As you can see there is alot of typing(or copy pasting) involve here and I want it to be more simple and easier to put in data. I was think an array would do but not sure how to do that yet. And also I need both of those 2 class, my teacher said something about having a super class and sub class of some sort. Anyway there you go, I hope someone could help me.
Okay, I got this assignment. I need to make a contact list that has an output like this:
Code:
Name City Home Cell Type Lisa Xiong Fresno 123-4567 987-5643 Friend Cathy Vang Fresno 191-6573 987-1546 Contact
Code:
//first class
class ContactDemo{
public static void main(String args[]){
Contact c1 = new Contact();
Contact c2 = new Contact();
Contact c3 = new Contact();
c1.name = "Name";
c1.city = "City";
c1.home = "Home";
c1.cell = "Cell";
c1.type = "Type";
c2.name = "Lisa Xiong";
c2.city = "Fresno";
c2.home = "123-4567";
c2.cell = "987-5643";
c2.type = "Friend";
c3.name = "Cathy Vang";
c3.city = "Fresno";
c3.home = "191-6573";
c3.cell = "987-1546";
c3.type = "Contact";
c1.showName();
System.out.print("\t");
c1.showCity();
System.out.print("\t");
c1.showHome();
System.out.print("\t");
c1.showCell();
System.out.print("\t");
c1.showType();
System.out.println();
c2.showName();
c2.showCity();
System.out.print("\t");
c2.showHome();
c2.showCell();
c2.showType();
System.out.println();
c3.showName();
c3.showCity();
System.out.print("\t");
c3.showHome();
c3.showCell();
c3.showType();
}
}
//second class
class Contact{
String name = "";
String city = "";
String home = "";
String cell = "";
String type = "";
void showName(){
System.out.print(name + "\t");
}
void showCity(){
System.out.print(city + "\t");
}
void showHome(){
System.out.print(home + "\t");
}
void showCell(){
System.out.print(cell + "\t");
}
void showType(){
System.out.print(type + "\t");
}
}
Comment