Answered Essay: Minimal Submitted Files You are required, but not limited, to turn in the follo

Minimal Submitted Files You are required, but not limited, to turn in the following source files: Assignment5.java (Download this file and use it as your driver program for this assignment. You need to add more codes to complete it.) Lamp.java FluorescentLamp.java LEDLamp.java LampParser.java

please help me fill the code of assignment5.

import java.io.*;   //to use InputStreamReader and BufferedReader
import java.util.*; //to use ArrayList

public class Assignment5
{
public static void main (String[] args)
{
char input1;
String inputInfo = new String();
String line = new String();
boolean operation;

// ArrayList object is used to store lamp objects
ArrayList <Lamp> lampList = new ArrayList<Lamp>();

try
{
printMenu();     // print out menu

// create a BufferedReader object to read input from a keyboard
InputStreamReader isr = new InputStreamReader (System.in);
BufferedReader stdin = new BufferedReader (isr);

do
{
System.out.println(“What action would you like to perform?”);
line = stdin.readLine().trim();
input1 = line.charAt(0);
input1 = Character.toUpperCase(input1);

if (line.length() == 1)
{
switch (input1)
{
case ‘A’:   //Add Lamp
System.out.print(“Please enter a lamp information to add:n”);
inputInfo = stdin.readLine().trim();
/***********************************************************************************
*** ADD your code here to create an object of one of child classes of Lamp class
*** and add it to the lampList
***********************************************************************************/
Lamp lamp = LampParser.parseStringToLamp(inputInfo);
lampList.add(lamp);
break;
case ‘C’:   //Compute Total Prices
/***********************************************************************************
*** ADD your code here to compute the total price for each lamp in the lampList.
***********************************************************************************/
for(int i =0; i<lampList.size(); i++)
{
((Lamp)lampList.get(i)).computeTotalPrice();
}
System.out.print(“total prices computedn”);
break;
case ‘D’:   //Search for Lamp
System.out.print(“Please enter a Lamp Name to search:n”);
inputInfo = stdin.readLine().trim();
operation = false;
/***********************************************************************************
*** ADD your code here to search the lamp with the entered lamp name and set operation
*** to true or false based on its result
***********************************************************************************/
for(int i =0; i<lampList.size(); i++)
{
if(((Lamp)lampList.get(i)).getLampName().equals(inputInfo))
{
operation = true;
break;
}

}
if (operation == true)
System.out.print(“lamp foundn”);
else
System.out.print(“lamp not foundn”);
break;
case ‘L’:   //List Lamps
/***********************************************************************************
*** ADD your code here to print out all lamp objects. If there is no lamp,
*** print “no lampn”
***********************************************************************************/
for(int i = 0; i<lampList.size(); i++)
{
System.out.print(lampList.get(i));

}
if(lampList.size()==0)
System.out.print(“no lampn”);
break;
case ‘Q’:   //Quit
break;
case ‘?’:   //Display Menu
printMenu();
break;
default:
System.out.print(“Unknown actionn”);
break;
}
}
else
{
System.out.print(“Unknown actionn”);
}
} while (input1 != ‘Q’); // stop the loop when Q is read
}
catch (IOException exception)
{
System.out.println(“IO Exception”);
}
}

/** The method printMenu displays the menu to a use **/
public static void printMenu()
{
System.out.print(“ChoicettActionn” +
“——tt——n” +
“AttAdd Lampn” +
“CttCompute Total Pricesn” +
“DttSearch for Lampn” +
“LttList Lampsn” +
“QttQuitn” +
“?ttDisplay Helpnn”);
}
}

Minimal Submitted Files You are required, but not limited, to turn in the following source files: Assignment5.java (Download this file and use it as your driver program for this assignment. You need to add more codes to complete it.) Lamp.java FluorescentLamp.java LEDLamp.java LampParser.java

Expert Answer

  • Assignment5.java
    import java.io.*; //to use InputStreamReader and BufferedReader

    import java.util.*; //to use ArrayList

    public class Assignment5

    {

    public static void main (String[] args)

    {

    char input1;

    String inputInfo = new String();

    String line = new String();

    boolean operation;

    // ArrayList object is used to store lamp objects

    ArrayList<Lamp> lampList = new ArrayList<Lamp>();

    try

    {

    printMenu(); // print out menu

    // create a BufferedReader object to read input from a keyboard

    InputStreamReader isr = new InputStreamReader (System.in);

    BufferedReader stdin = new BufferedReader (isr);

    do

    {

    System.out.println(“What action would you like to perform?”);

    line = stdin.readLine().trim();

    input1 = line.charAt(0);

    input1 = Character.toUpperCase(input1);

    if (line.length() == 1)

    {

    switch (input1)

    {

    case ‘A’: //Add Lamp

    System.out.print(“Please enter some lamp information to add:n”);

    inputInfo = stdin.readLine().trim();

    /***********************************************************************************

    *** Code here to create an object of one of child classes of Lamp class

    *** and add it to the lampList

    ***********************************************************************************/

    Lamp lamp = LampParser.parseStringToLamp(inputInfo);

    lampList.add(lamp);

    System.out.println(“Lamp added successfullyn”);

    break;

    case ‘C’: //Compute Total Prices

    /***********************************************************************************

    *** Code here to compute the total price for each lamp in the lampList.

    ***********************************************************************************/

    double totalPrice = 0;

    for(int i = 0; i < lampList.size(); i++)

    {

    lampList.get(i).computeTotalPrice();

    totalPrice += lampList.get(i).getTotalPrice();

    }

    System.out.printf(“Total Price of the lamps: $%.2fnn”, totalPrice);

    break;

    case ‘D’: //Search for Lamp

    System.out.print(“Please enter a Lamp Name to search:n”);

    inputInfo = stdin.readLine().trim();

    operation = false;

    /***********************************************************************************

    *** Code here to search the lamp with the entered lamp name and set operation

    *** to true or false based on its result

    ***********************************************************************************/

    boolean flag = false;

    for(int i = 0; i < lampList.size(); i++)

    {

    if(lampList.get(i).getLampName().equalsIgnoreCase(inputInfo))

    {

    flag = true;

    System.out.println(lampList.get(i));

    }

    }

    if(flag == false)

    {

    System.out.println(“Presently, there is no lamp with that namen”);

    }

    break;

    case ‘L’: //List Lamps

    /***********************************************************************************

    *** Code here to print out all lamp objects. If there is no lamp,

    *** print “no lampn”

    ***********************************************************************************/

    int len = lampList.size();

    if(len == 0)

    System.out.println(“No lamp to print.”);

    else

    {

    for(int i = 0; i < len; i++)

    {

    System.out.println(lampList.get(i));

    }

    }

    break;

    case ‘Q’: //Quit

    break;

    case ‘?’: //Display Menu

    printMenu();

    break;

    default:

    System.out.print(“Unknown actionn”);

    break;

    }

    }

    else

    {

    System.out.print(“Unknown actionn”);

    }

    } while (input1 != ‘Q’); // stop the loop when Q is read

    }

    catch (IOException exception)

    {

    System.out.println(“IO Exception”);

    }

    }

    /** The method printMenu displays the menu to a use **/

    public static void printMenu()

    {

    System.out.print(“ChoicettActionn” +

    “——tt——n” +

    “AttAdd Lampn” +

    “CttCompute Total Pricesn” +

    “DttSearch for Lampn” +

    “LttList Lampsn” +

    “QttQuitn” +

    “?ttDisplay Helpnn”);

    }

    }

    Lamp.java
    import java.text.NumberFormat;

    import java.util.Currency;

    import java.util.Locale;

    public abstract class Lamp {

    private int quantity;

    private double unitPrice;

    private double totalPrice;

    private String lampName;

    public Lamp(String lName, double someUnitPrice, int q)

    {

    this.lampName = lName;

    this.unitPrice = someUnitPrice;

    this.quantity = q;

    this.totalPrice = 0.0;

    }

    public String getLampName()

    {

    return this.lampName;

    }

    public double getUnitPrice()

    {

    return this.unitPrice;

    }

    public int getQuantity()

    {

    return this.quantity;

    }

    public double getTotalPrice()

    {

    return this.totalPrice;

    }

    public void setTotalPrice(double totalPrice)

    {

    this.totalPrice = totalPrice;

    }

    public abstract void computeTotalPrice();

    public String toString()

    {

    computeTotalPrice();

    Currency us_dollar = Currency.getInstance(“USD”);

    NumberFormat formatter = NumberFormat.getCurrencyInstance(Locale.US);

    formatter.setCurrency(us_dollar);

    return “nLamp Name:tt” + this.lampName + “n Quantity:tt” + this.quantity+ “n”+

    “Unit Price:tt” + this.unitPrice + “n Total Price:tt” +formatter.format(this.getTotalPrice())+” ” + us_dollar.getCurrencyCode()+ “n”;

    }

    }

    FluorescentLamp.java
    import java.text.NumberFormat;

    import java.util.Currency;

    import java.util.Locale;

    public class FluorescentLamp extends Lamp {

    private double recycleFee;

    public FluorescentLamp(String lName, double someUnitPrice, int q, double fee) {

    super(lName, someUnitPrice, q);

    this.recycleFee = fee;

    }

    @Override

    public void computeTotalPrice() {

    double lampPrice = super.getUnitPrice() + this.recycleFee;

    double totalPrice = super.getQuantity() * lampPrice;

    super.setTotalPrice(totalPrice);

    }

    public String toString()

    {

    computeTotalPrice();

    Currency us_dollar = Currency.getInstance(“USD”);

    NumberFormat formatter = NumberFormat.getCurrencyInstance(Locale.US);

    formatter.setCurrency(us_dollar);

    return “nFluorescent Lamp”+”n Recycle Fee:tt”+

    this.recycleFee+ “n Lamp Name:tt” + this.getLampName()+

    “n Quantity:tt” + this.getQuantity() + “n” +

    “Unit Price:tt” + this.getUnitPrice()+

    “n Total Price:tt “+formatter.format(this.getTotalPrice())+” ” + us_dollar.getCurrencyCode()+ “n”;

    }

    }

    LedLamp.java
    import java.text.NumberFormat;

    import java.util.Currency;

    import java.util.Locale;

    public class LedLamp extends Lamp {

    private double energySavingRebate ;

    public LedLamp(String lName, double someUnitPrice, int q, double rebate) {

    super(lName, someUnitPrice, q);

    this.energySavingRebate = rebate;

    }

    @Override

    public void computeTotalPrice() {

    double lampPrice =super.getUnitPrice() – ( super.getUnitPrice() * this.energySavingRebate );

    double totalPrice = super.getQuantity() * lampPrice;

    super.setTotalPrice(totalPrice);

    }

    public String toString()

    {

    computeTotalPrice();

    Currency us_dollar = Currency.getInstance(“USD”);

    NumberFormat formatter = NumberFormat.getCurrencyInstance(Locale.US);

    formatter.setCurrency(us_dollar);

    return “nLED Lampn”+

    “Energy Savings Rebate:t”+ (this.energySavingRebate*100)+ “%”

    +”n Lamp Name:tt”+ this.getLampName()+

    “n Quantity:tt”+this.getQuantity() + “n”+

    “Unit Price:tt”+ this.getUnitPrice() + “n”+

    “Total Price:tt” + formatter.format(this.getTotalPrice())+” ” + us_dollar.getCurrencyCode()+ “n”;

    }

    }

    LampParser.java
    public class LampParser {

    public static Lamp parseStringToLamp(String lineToParse)

    {

    String[] lampData = lineToParse.split(“/”);

    if(lampData[0].equalsIgnoreCase(“Fluorescent”))

    {

    double unitPrice = Double.parseDouble(lampData[2]);

    int q = Integer.parseInt(lampData[3]);

    double recycleFee = Double.parseDouble(lampData[4]);

    return new FluorescentLamp(lampData[1], unitPrice, q, recycleFee);

    }

    else

    {

    double unitPrice = Double.parseDouble(lampData[2]);

    int q = Integer.parseInt(lampData[3]);

    double energySavingRebate = Double.parseDouble(lampData[4]);

    return new LedLamp(lampData[1], unitPrice, q, energySavingRebate);

    }

    }

    }

    OUTPUT

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.