package templates; import java.util.*; public classTemplates1Main { /** * @param
ID: 3617484 • Letter: P
Question
package templates;
import java.util.*;
public classTemplates1Main
{
/**
* @param args the command linearguments
*/
public static void main(String[] args)
{
Scanner input = newScanner(System.in);
Stringfnames[] = {"Maury", "Elizabeth"};
String lnames[] ={"Spearman", "Walker"};
int ages[] = {41,65};
String typeOfBooks[] ={"Java", "CPP"};
double prices[] ={25.00, 35.00};
Stringfname[] = {"Marry", "Houston"};
String lname[] ={"Spear", "Williams"};
int age[] = {36,55};
String typeofShoes[] ={"boots", "tennis shoes"};
double price[] = {25.00,35.00};
ArrayList<Product>ts = new ArrayList<Product>();
for(intj=0;j<lnames.length;j++)
ts.add(newBooks(fnames[j], lnames[j], ages[j], typeOfBooks[j],prices[j]));
for(int k=0;k<lname.length;k++)
ts.add(newShoes(fname[k], lname[k], ages[k], typeofShoes[k],price[k]));
intrelease, j;
}
abstract class Product
{
protected static int count = 101;
protected int age;
protected String FName;
protected String LName;
protected int ccnt;
publicProduct(String fn, String ln, int ag)
{
ccnt = count++;
FName = fn;
LName = ln;
age = ag;
}
public abstract void display();
public abstract int getId();
}
class Shoes extends Product
{
private String shoesType;
private double price;
public Shoes(String fname, String lname, int ag, String bktype,double pric)
{
super(fname,lname, ag);
shoesType = bktype;
price = pric;
}
public void display()
{
System.out.printf("%-15s %-15s %-15d %-15s %-15.2f %d ", FName,LName, age, shoesType, price, ccnt);
}
public int getId()
{
return(ccnt);
}
}
class Books extends Product
{
private String bookType;
private double price;
public Books(String fname, String lname, int ag, String bktype,double pric)
{
super(fname,lname, ag);
bookType = bktype;
price = pric;
}
public void display()
{
System.out.printf("%-15s %-15s %-15d %-15s %-15.2f %d ", FName,LName, age, bookType, price, ccnt);
}
public int getId()
{
return(ccnt);
}
}
Explanation / Answer
import java.util.*;
public class Templates1Main
{
public static voidmain(String[] args)
{
Scanner input = newScanner(System.in);
String fnames[] = {"Maury","Elizabeth"};
String lnames[] ={"Spearman", "Walker"};
int ages[] = {41, 65};
String typeOfBooks[] ={"Java", "CPP"};
double prices[] = {25.00,35.00};
String fname[] = {"Marry","Houston"};
String lname[] = {"Spear","Williams"};
int age[] = {36, 55};
String typeofShoes[] ={"boots", "tennis shoes"};
double price[] = {25.00,35.00};
ArrayList<Product>ts =new ArrayList<Product>();
for(intj=0;j<lnames.length;j++)
ts.add(new Books(fnames[j],lnames[j], ages[j], typeOfBooks[j], prices[j]));
for(intk=0;k<lname.length;k++)
ts.add(new Shoes(fname[k],lname[k], ages[k], typeofShoes[k], price[k]));
int release, j;
Iterator<Product> i =ts.iterator();
while(i.hasNext())
{
Product p =i.next();
p.display();
}
System.out.print(" Enter theemployee id number: ");
release =input.nextInt(); int index=0;
while(i.hasNext())
{
Product p =i.next(); if(p.getId() ==release) { ts.remove(index); System.out.print("Entery Removed"); } index++;
}
}
}
abstract class Product
{
protected static int count = 101;
protected int age;
protected String FName;
protected String LName;
protected int ccnt;
public Product(String fn, String ln, intag)
{
ccnt = count++;
FName = fn;
LName = ln;
age = ag;
}
public abstract void display();
public abstract int getId();
}
class Shoes extends Product
{
private String shoesType;
private double price;
public Shoes(String fname, String lname,int ag, String bktype, double pric)
{
super(fname, lname,ag);
shoesType = bktype;
price = pric;
}
public void display()
{
System.out.printf("%-15s%-15s %-15d %-15s %-15.2f %d ", FName, LName, age, shoesType,price, ccnt);
}
public int getId()
{
return(ccnt);
}
}
class Books extends Product
{
private String bookType;
private double price;
public Books(String fname, String lname,int ag, String bktype, double pric)
{
super(fname, lname,ag);
bookType = bktype;
price = pric;
}
public void display()
{
System.out.printf("%-15s%-15s %-15d %-15s %-15.2f %d ", FName, LName, age, bookType,price, ccnt);
}
public int getId()
{
return(ccnt);
}
}
import java.util.*;
public class Templates1Main
{
public static voidmain(String[] args)
{
Scanner input = newScanner(System.in);
String fnames[] = {"Maury","Elizabeth"};
String lnames[] ={"Spearman", "Walker"};
int ages[] = {41, 65};
String typeOfBooks[] ={"Java", "CPP"};
double prices[] = {25.00,35.00};
String fname[] = {"Marry","Houston"};
String lname[] = {"Spear","Williams"};
int age[] = {36, 55};
String typeofShoes[] ={"boots", "tennis shoes"};
double price[] = {25.00,35.00};
ArrayList<Product>ts =new ArrayList<Product>();
for(intj=0;j<lnames.length;j++)
ts.add(new Books(fnames[j],lnames[j], ages[j], typeOfBooks[j], prices[j]));
for(intk=0;k<lname.length;k++)
ts.add(new Shoes(fname[k],lname[k], ages[k], typeofShoes[k], price[k]));
int release, j;
Iterator<Product> i =ts.iterator();
while(i.hasNext())
{
Product p =i.next();
p.display();
}
System.out.print(" Enter theemployee id number: ");
release =input.nextInt(); int index=0;
while(i.hasNext())
{
Product p =i.next(); if(p.getId() ==release) { ts.remove(index); System.out.print("Entery Removed"); } index++;
}
}
}
abstract class Product
{
protected static int count = 101;
protected int age;
protected String FName;
protected String LName;
protected int ccnt;
public Product(String fn, String ln, intag)
{
ccnt = count++;
FName = fn;
LName = ln;
age = ag;
}
public abstract void display();
public abstract int getId();
}
class Shoes extends Product
{
private String shoesType;
private double price;
public Shoes(String fname, String lname,int ag, String bktype, double pric)
{
super(fname, lname,ag);
shoesType = bktype;
price = pric;
}
public void display()
{
System.out.printf("%-15s%-15s %-15d %-15s %-15.2f %d ", FName, LName, age, shoesType,price, ccnt);
}
public int getId()
{
return(ccnt);
}
}
class Books extends Product
{
private String bookType;
private double price;
public Books(String fname, String lname,int ag, String bktype, double pric)
{
super(fname, lname,ag);
bookType = bktype;
price = pric;
}
public void display()
{
System.out.printf("%-15s%-15s %-15d %-15s %-15.2f %d ", FName, LName, age, bookType,price, ccnt);
}
public int getId()
{
return(ccnt);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.