Question
Someone already answered Task#1 question. There is a Person class. I'm stuck on Task #2 and have include my code below: - infact I probably
Someone already answered Task#1 question. There is a Person class.
I'm stuck on Task #2 and have include my code below: - infact I probably will need help with the other task. Liking Java so far, arrays - not so much.
import java.text.*; // to use Decimal Format
public class TwoD_ArrayDriver
{
public static void main(String[] args)
{
DecimalFormat myFormat;
// to get 2 decimals every time
myFormat = new DecimalFormat("#.00");
Person p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21;
p1 = new Person("Abby", "Arthur"); p2 = new Person("Bubba","Brown"); p3 = new Person("Chuckie", "Cheese"); p4 = new Person("Don", "Drysdale"); p5 = new Person("Ernie","Eastwood");
p6 = new Person("Flo", "Fauntroy"); p7 = new Person("Gabby", "Giffords"); p8 = new Person("Hank","Hoover"); p9 = new Person("Indy", "Imhauf"); p10 = new Person("Jim","Jones");
p11 = new Person("Ken", "Koopman"); p12 = new Person("Larry", "Lancelot"); p13 = new Person("Michael", "Moore" ); p14 = new Person("Nina","Nonesuch"); p15 = new Person("Oscar","OToole");
p16 = new Person("Pat","Pompous"); p17 = new Person("Quincy","Quinton"); p18 = new Person("Ralph","Rancid"); p19 = new Person("Steven","Simpson"); p20 = new Person("Tim","Tinker");
p21 = new Person("Uncle","Usher");
Person[] allPersons = {p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21};
Person[] mondayAppts = {p1, p2, p3, p4, p5};
Person[] tuesdayAppts = {p6, p7, p8};
Person[] wednesdayAppts = {p9, p10, p11, p12};
Person[] thursdayAppts = {p13, p14, p15, p16, p17};
Person[] fridayAppts = {p18, p19, p20, p21};
//Task #1 Print the id, first name, and last name of Person #7, using tuesdayAppts
int intToPrint = 0;
String fNameToPrint = "unknown";
String lNameToPrint = "unknown";
System.out.println("Person #7 "+ p7.ID +" "+ p7.fName + " "+ p7.lName);
//Task #2 Create a 2D array out of the 1D arrays
//begin my code.
Person [][] weeklyAppts = new Person [5][5];
for (int row= 0; row < 5; row ++) //days of week
{
for (int col = 0; col < 5; col ++) //persons
{
weeklyAppts [row] [col] = ??????
}
} //end my code
//Task #3 Print the id of Person #8, using weeklyAppts
intToPrint = 0;
fNameToPrint = "unknown";
lNameToPrint = "unknown";
System.out.println("Person #8's ID "+intToPrint+" "+ fNameToPrint +" "+lNameToPrint);
//Task #4 Print the length of thursdayAppts using weeklyAppts
intToPrint = 0;
System.out.println("Length of Thursday's appts "+intToPrint);
//Task #5 Print all using weeklyAppts
int ctr = 1;
for (int i=0; i<2; i++) {
for (int j=0; j<2; j++) {
intToPrint = 0;
fNameToPrint = "unknown";
lNameToPrint = "unknown";
System.out.println("Appt #"+(ctr++)+" "+intToPrint+" "+fNameToPrint+" "+lNameToPrint);
}
}
}
}
The Person Class;
public class Person {
String fName;
String lName;
int ID;
static int nextID = 101;
Person() {
fName = "unk";
lName = "unk";
ID = nextID++;
}
Person(String fName, String lName) {
this.fName = fName;
this.lName = lName;
ID = nextID++;
}
public void setFName(String fName) {
this.fName = fName;
}
public String getFName() {
return fName;
}
public void setLName(String lName) {
this.lName = lName;
}
public String getLName() {
return lName;
}
public int getID() {
return ID;
}
}
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