The management of BooksRUs has submitted two requests. The first is for a mailin
ID: 3727193 • Letter: T
Question
The management of BooksRUs has submitted two requests. The first is for a mailing list of all customers stored in the CUSTOMERS table The second is for a list of the percentage of profit generated by each book in the BOOKS table The requests are as follows reate a mailing list from the CUSTOMERS table. The mailing list should display the name, address, city, state, and zip code for each customer. Each customer's name should be listed in order of last name followed by first name with a comma, and have the column header "Name." The city and state should be listed as one column of output, with the values separated by a comma and the column header "Location."Explanation / Answer
import java.io.*;
import java.util.*;
public class MyCode {
private static ArrayList<People> arrayListPeople;
public static void main (String[] args) {
System.out.println("Hello Java");
arrayListPeople = new ArrayList<People>(1000);
GetChoice();
}
private static void DisplayAll(String typeOfDisplay)
{
for(int i = 0; i < arrayListPeople.size(); i++)
{
Class cls = arrayListPeople.get(i).getClass();
if(cls.getName().equals(typeOfDisplay))
{
arrayListPeople.get(i).toString();
}
}
}
private static void GetChoice()
{
System.out.println("A. Add a Person");
System.out.println("B. Add a Politician");
System.out.println("C. Add a Farmer");
System.out.println("D. Add a Lawyer");
System.out.println("E. Add a Doctor");
System.out.println("F. Display all People");
System.out.println("G. Display all Politicians");
System.out.println("H. Display all Lawyers");
System.out.println("I. Display all Doctors");
System.out.println("J. Exit Program");
String choice = "";
Scanner sc = new Scanner(System.in);
choice = sc.nextLine();
switch(choice)
{
case "A":
arrayListPeople.add(People.CreateInstance());
break;
case "B":
arrayListPeople.add(Politician.CreateInstance());
break;
case "C":
arrayListPeople.add(Farmer.CreateInstance());
break;
case "D":
arrayListPeople.add(Lawyer.CreateInstance());
break;
case "E":
arrayListPeople.add(Doctor.CreateInstance());
break;
case "F":
DisplayAll("People");
break;
case "G":
DisplayAll("Politicians");
break;
case "H":
DisplayAll("Lawyers");
break;
case "I":
DisplayAll("Doctors");
break;
case "J":
System.exit(0);
}
}
}
public class People
{
public People()
{
}
private String name;
public String getName()
{
return this.name;
}
public void setName(String name)
{
this.name = name.toUpperCase();
}
private int age;
public int getAge()
{
return this.age;
}
public void setAge(int age)
{
if(age > 0 || age < 125)
{
}
this.age = age;
}
public static People CreateInstance()
{
return new People();
}
public String toString()
{
return String.format("Name..................."+name+" "+"Age................"+age);
}
}
public class Politician extends People
{
public Politician()
{
}
String party;
boolean honest;
private String position;
public String getPosition()
{
return this.position;
}
public void setPosition(String position)
{
this.position = position.toLowerCase();
}
public static Politician CreateInstance()
{
return new Politician();
}
public String toString()
{
super.toString();
String partyType = "";
if(party.equals("D"))
partyType = "Democrate";
if(party.equals("R"))
partyType = "Republic";
if(party.equals("I"))
partyType = "Independent";
return String.format("Party..................."+partyType+" "+"Honest................."+honest+" "+"Position................"+position);
}
}
public class Farmer extends Politician
{
public Farmer()
{
}
String farmType;
private double noAcres;
public double getNoAcres()
{
return this.noAcres;
}
public void setNoAcres(double noAcres)
{
if(noAcres > 1 || noAcres < 1000)
{
}
this.noAcres = noAcres;
}
public static Farmer CreateInstance()
{
return new Farmer();
}
public String toString()
{
super.toString();
return String.format("Farm Type..................."+farmType+" "+"No. of Acres................"+noAcres);
}
}
public class Lawyer extends Politician
{
public Lawyer()
{
}
String Speciality;
String lawSchool;
public String toString()
{
super.toString();
return String.format("Speciality..................."+Speciality+" "+"Law School................"+lawSchool);
}
public static Lawyer CreateInstance()
{
return new Lawyer();
}
}
public class Doctor extends Politician
{
public Doctor()
{
}
boolean surgeon;
double studentLoanDebt;
public double getStudentLoanDebt()
{
return this.studentLoanDebt;
}
public void setStudentLoanDebt(double studentLoanDebt)
{
if(studentLoanDebt > 1 || studentLoanDebt < 500000)
{
}
this.studentLoanDebt = studentLoanDebt;
}
public static Doctor CreateInstance()
{
return new Doctor();
}
public String toString()
{
super.toString();
return String.format("Surgeon..................."+surgeon+" "+"Student Loan Debt................"+studentLoanDebt);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.