Question

In: Computer Science

this a continuation of my previous question. answer with Java programming language and Netbeans idk 1,...

this a continuation of my previous question.

answer with Java programming language and Netbeans idk

1, 2, 3, 4)

CODE

class Device {

private String serialNumber, color, manufacturer;

private double outputPower;

public Device () {

serialNumber = "";

color = "";

manufacturer = "";

outputPower = 0.0;

}

public Device(String serialNumber, String color, String manufacturer, double outputPower) {

this.serialNumber = serialNumber;

this.color = color;

this.manufacturer = manufacturer;

this.outputPower = outputPower;

}

public String getSerialNumber() {

return serialNumber;

}

public void setSerialNumber(String serialNumber) {

this.serialNumber = serialNumber;

}

public String getColor() {

return color;

}

public void setColor(String color) {

this.color = color;

}

public String getManufacturer() {

return manufacturer;

}

public void setManufacturer(String manufacturer) {

this.manufacturer = manufacturer;

}

public double getOutputPower() {

return outputPower;

}

public void setOutputPower(double outputPower) {

this.outputPower = outputPower;

}

@Override

public String toString() {

return "Device [serialNumber=" + serialNumber + ", color=" + color + ", manufacturer=" + manufacturer

+ ", outputPower=" + outputPower + "]";

}

}

interface AutomationInterface {

enum Power {

ON,

OFF

}

float RFpowerRatio(int inputPower);

double powerUsage(int hours, int costPerKWH);

}

class Television extends Device {

private String type;

private int screenSize;

public Television(String type, int screenSize) {

super();

this.type = type;

this.screenSize = screenSize;

}

public Television(String serialNumber, String color, String manufacturer, double outputPower, String type,

int screenSize) {

super(serialNumber, color, manufacturer, outputPower);

this.type = type;

this.screenSize = screenSize;

}

public String getType() {

return type;

}

public void setType(String type) {

this.type = type;

}

public int getScreenSize() {

return screenSize;

}

public void setScreenSize(int screenSize) {

this.screenSize = screenSize;

}

@Override

public String toString() {

return "Television [type=" + type + ", screenSize=" + screenSize + "]";

}

}

class ElectricOven extends Device{

private int numberOfPlates;

private boolean containsGrill;

public ElectricOven(int numberOfPlates, boolean containsGrill) {

super();

this.numberOfPlates = numberOfPlates;

this.containsGrill = containsGrill;

}

public ElectricOven(String serialNumber, String color, String manufacturer, double outputPower, int numberOfPlates,

boolean containsGrill) {

super(serialNumber, color, manufacturer, outputPower);

this.numberOfPlates = numberOfPlates;

this.containsGrill = containsGrill;

}

public int getNumberOfPlates() {

return numberOfPlates;

}

public void setNumberOfPlates(int numberOfPlates) {

this.numberOfPlates = numberOfPlates;

}

public boolean isContainsGrill() {

return containsGrill;

}

public void setContainsGrill(boolean containsGrill) {

this.containsGrill = containsGrill;

}

@Override

public String toString() {

return "ElectricOven [numberOfPlates=" + numberOfPlates + ", containsGrill=" + containsGrill + "]";

}

}

class LEDBulb extends Device {

private String plugType;

public LEDBulb(String plugType) {

super();

this.plugType = plugType;

}

public LEDBulb(String serialNumber, String color, String manufacturer, double outputPower, String plugType) {

super(serialNumber, color, manufacturer, outputPower);

this.plugType = plugType;

}

public String getPlugType() {

return plugType;

}

public void setPlugType(String plugType) {

this.plugType = plugType;

}

@Override

public String toString() {

return "LEDBulb [plugType=" + plugType + "]";

}

}

5. Implement the AutomationInterface in all 3 classes defined in step 3 and
hence adding implementation to the methods outlined in step 2.
(a) RF Power ratio is the ratio between output power and input power. In
electronics devices with negative RF are considered a hazard and positive
RF as safe. Hence
RF =
POWERout
POWERin
(b) Power usage calculates the total cost of power used by the device. The
output power needs to be converted to kilowatts (divide by 1000) before
doing the calculation below:
PewerUsage = outputPower hours costP erKWH
Faculty of Computing and Informatics, Department of Computer Science
OOP521S: Individual Lab
6. In the driver class create an arraylist of type Device, and add 3 TVs, 2 Ovens,
and 3 Bulbs whereby each of those instances make reference to Device. Note
that this is demonstration of polymorphism.
7. Print out each of the objects using a custom toString() method in each of those
classes.
8. Make use of RF ratio to printout all devices that are a hazard to use.
9. Sort the Device array based on the PowerUsage, starting with the lowest consumption
first and the highest consumption last.

Solutions

Expert Solution

//Please change the input in Main class according to your testing criteria

//Java code

public class Device implements AutomationInterface {

    private String serialNumber, color, manufacturer;

    private double outputPower;

    public Device () {

        serialNumber = "";

        color = "";

        manufacturer = "";

        outputPower = 0.0;

    }

    @Override
    public double powerUsage(int hours, int costPerKWH) {
        double powerUsage = (outputPower*hours*costPerKWH)/1000;
        return powerUsage;
    }

    @Override
    public float RFpowerRatio(int inputPower) {
        float RF = (float) (outputPower/inputPower);
        RF = (float) Math.log10(RF);
        return RF;
    }

    public Device(String serialNumber, String color, String manufacturer, double outputPower) {

        this.serialNumber = serialNumber;

        this.color = color;

        this.manufacturer = manufacturer;

        this.outputPower = outputPower;

    }

    public String getSerialNumber() {

        return serialNumber;

    }

    public void setSerialNumber(String serialNumber) {

        this.serialNumber = serialNumber;

    }

    public String getColor() {

        return color;

    }

    public void setColor(String color) {

        this.color = color;

    }

    public String getManufacturer() {

        return manufacturer;

    }

    public void setManufacturer(String manufacturer) {

        this.manufacturer = manufacturer;

    }

    public double getOutputPower() {

        return outputPower;

    }

    public void setOutputPower(double outputPower) {

        this.outputPower = outputPower;

    }

    @Override

    public String toString() {

        return "Device [serialNumber=" + serialNumber + ", color=" + color + ", manufacturer=" + manufacturer

                + ", outputPower=" + outputPower + "]";

    }

}

//=========================================================

public interface AutomationInterface {

    enum Power {

        ON,

        OFF

    }
    float RFpowerRatio(int inputPower);

    double powerUsage(int hours, int costPerKWH);

}

//======================================================

public class Television extends Device implements AutomationInterface{

    private String type;

    private int screenSize;

    public Television(String type, int screenSize) {

        super();

        this.type = type;

        this.screenSize = screenSize;

    }

    public Television(String serialNumber, String color, String manufacturer, double outputPower, String type,

                      int screenSize) {

        super(serialNumber, color, manufacturer, outputPower);

        this.type = type;

        this.screenSize = screenSize;

    }

    public String getType() {

        return type;

    }

    public void setType(String type) {

        this.type = type;

    }

    public int getScreenSize() {

        return screenSize;

    }

    public void setScreenSize(int screenSize) {

        this.screenSize = screenSize;

    }

    @Override

    public String toString() {

        return "Television [type=" + type + ", screenSize=" + screenSize + "]";

    }

    /**
     * RF Power ratio is the ratio between output power and input power. In
     * electronics devices with negative RF are considered a hazard and positive
     * RF as safe. Hence
     * RF =
     * POWERout
     * POWERin
     * @param inputPower
     * @return
     */
    @Override
    public float RFpowerRatio(int inputPower) {
        float RF = (float) (getOutputPower()/inputPower);
        RF = (float) Math.log10(RF);
        return RF;
    }

    /**
     * Power usage calculates the total cost of power used by the device. The
     * output power needs to be converted to kilowatts (divide by 1000) before
     * doing the calculation below:
     * @param hours
     * @param costPerKWH
     * @return
     */
    @Override
    public double powerUsage(int hours, int costPerKWH) {
        //PewerUsage = outputPower hours costP erKWH
        double powerUsage = (getOutputPower()*hours*costPerKWH)/1000;
        return powerUsage;
    }
}

//=================================================

public class ElectricOven extends Device implements AutomationInterface{

    private int numberOfPlates;

    private boolean containsGrill;

    public ElectricOven(int numberOfPlates, boolean containsGrill) {

        super();

        this.numberOfPlates = numberOfPlates;

        this.containsGrill = containsGrill;

    }

    public ElectricOven(String serialNumber, String color, String manufacturer, double outputPower, int numberOfPlates,

                        boolean containsGrill) {

        super(serialNumber, color, manufacturer, outputPower);

        this.numberOfPlates = numberOfPlates;

        this.containsGrill = containsGrill;

    }

    public int getNumberOfPlates() {

        return numberOfPlates;

    }

    public void setNumberOfPlates(int numberOfPlates) {

        this.numberOfPlates = numberOfPlates;

    }

    public boolean isContainsGrill() {

        return containsGrill;

    }

    public void setContainsGrill(boolean containsGrill) {

        this.containsGrill = containsGrill;

    }

    @Override

    public String toString() {

        return "ElectricOven [numberOfPlates=" + numberOfPlates + ", containsGrill=" + containsGrill + "]";

    }

    @Override
    public float RFpowerRatio(int inputPower) {
        float RF = (float) (getOutputPower()/inputPower);
        RF = (float) Math.log10(RF);
        return RF;
    }

    @Override
    public double powerUsage(int hours, int costPerKWH) {
        double powerUsage = (getOutputPower()*hours*costPerKWH)/1000;
        return powerUsage;
    }
}

//==========================================

public class LEDBulb extends Device implements AutomationInterface {

    private String plugType;

    public LEDBulb(String plugType) {

        super();

        this.plugType = plugType;

    }

    public LEDBulb(String serialNumber, String color, String manufacturer, double outputPower, String plugType) {

        super(serialNumber, color, manufacturer, outputPower);

        this.plugType = plugType;

    }

    public String getPlugType() {

        return plugType;

    }

    public void setPlugType(String plugType) {

        this.plugType = plugType;

    }

    @Override

    public String toString() {

        return "LEDBulb [plugType=" + plugType + "]";

    }

    @Override
    public float RFpowerRatio(int inputPower) {
        float RF = (float) (getOutputPower()/inputPower);
        RF = (float) Math.log10(RF);
        return RF;
    }

    @Override
    public double powerUsage(int hours, int costPerKWH) {
        double powerUsage = (getOutputPower()*hours*costPerKWH)/1000;
        return powerUsage;
    }
}

//=======================================

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class Main {
    public static void main(String[] args)
    {

        ArrayList<Device> devices = new ArrayList<>();
        //Add objects to arrayList
        /**
         * add 3 TVs, 2 Ovens,
         * and 3 Bulb
         */
        devices.add(new Television("TV1001","Black","Samsung",230,"Electronic",19));
        devices.add(new Television("TV1002","Grey","Micromax",450,"Electronic",29));
        devices.add(new Television("TV1002","White","Sony",350,"Electronic",55));
        //Ovens
        devices.add(new ElectricOven("Oven1001","Silver","Philips",350,2,false));
        devices.add(new ElectricOven("Oven1002","White","Samsung",450,3,true));
        //Bulbs
        devices.add(new LEDBulb("LED1001","White","Philips",230,"Traditional"));
        devices.add(new LEDBulb("LED1002","Silver","Syska",230,"Traditional"));
        devices.add(new LEDBulb("LED1003","Green","Crompton",230,"Traditional"));

        /**
         * Print out each of the objects using a custom toString() method in each of those
         */
        System.out.println("Devices Info: \n");
        for (Device d:devices
        ) {

                System.out.println(d);
        }
/**
 * use of RF ratio to printout all devices that are a hazard to use.
 */
System.out.println("\nall devices that are a hazard to use");
        for (Device d:devices
             ) {
            // negative RF are considered a hazard
            if(d.RFpowerRatio(2000)<0)
                System.out.println(d);
        }
        /**
         * Sort the Device array based on the PowerUsage, starting with the lowest consumption
         * first and the highest consumption last.
         */
        Collections.sort(devices, new Comparator<Device>() {
            @Override
            public int compare(Device o1, Device o2) {
                if(o1.powerUsage(20,350)>o2.powerUsage(20,350))
                    return 1;
                else  if(o1.powerUsage(20,350)<o2.powerUsage(20,350))
                    return -1;
                else
                    return 0;
            }
        });
        System.out.println("\nAfter sort: ");
        for (Device d:devices
        ) {

                System.out.println(d);
        }
    }
}

//Output

//if you need any help regarding this solution .......... please leave a comment ........... thanks


Related Solutions

Answer the following in Java programming language Create a Java Program that will import a file...
Answer the following in Java programming language Create a Java Program that will import a file of contacts (contacts.txt) into a database (Just their first name and 10-digit phone number). The database should use the following class to represent each entry: public class contact {    String firstName;    String phoneNum; } Furthermore, your program should have two classes. (1) DatabaseDirectory.java:    This class should declare ArrayList as a private datafield to store objects into the database (theDatabase) with the...
***Please answer the question using the JAVA programming language. Write a program that calculates mileage reimbursement...
***Please answer the question using the JAVA programming language. Write a program that calculates mileage reimbursement for a salesperson at a rate of $0.35 per mile. Your program should interact (ask the user to enter the data) with the user in this manner: MILEAGE REIMBURSEMENT CALCULATOR Enter beginning odometer reading > 13505.2 Enter ending odometer reading > 13810.6 You traveled 305.4 miles. At $0.35 per mile, your reimbursement is $106.89. ** Extra credit 6 points: Format the answer (2 points),...
The programming language that is being used here is JAVA, below I have my code that...
The programming language that is being used here is JAVA, below I have my code that is supposed to fulfill the TO-DO's of each segment. This code in particular has not passed 3 specific tests. Below the code, the tests that failed will be written in bold with what was expected and what was outputted. Please correct the mistakes that I seem to be making if you can. Thank you kindly. OverView: For this project, you will develop a game...
java language NetBeans Write a program that prompts the user to enter the weight of a...
java language NetBeans Write a program that prompts the user to enter the weight of a person in kilograms and outputs the equivalent weight in pounds. Output both the weights rounded to two decimal places. (Note that 1 kilogram = 2.2 pounds.) Format your output with two decimal places.
In java, follow the methods in bold First, launch NetBeans and close any previous projects that...
In java, follow the methods in bold First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects). Then create a new Java application called "WeightedAvgDataAnalyzer" (without the quotation marks), that modifies the DataAnalyzer.java in Horstmann Section 7.5, pp. 350-351 according to the specifications below. The input file should be called 'data.txt' and should be created according to the highlighted instructions below. Note that even though you know...
THE QUESTION IS OF JAVA LANGUAGE. ANSWER IS REQUIRED IN THREE PARTS (THREE JAVA FILES). PLEASE...
THE QUESTION IS OF JAVA LANGUAGE. ANSWER IS REQUIRED IN THREE PARTS (THREE JAVA FILES). PLEASE DIFFERENTIATE FILES SO I CAN UNDERSTAND BETTER. NOTE - Submission in parts. Parts required - Dog Class Code, Dog Manager Class Code and the main code. Please differentiate all three in the answer. This Assignment is designed to take you through the process of creating basic classes, aggregation and manipulating arrays of objects. Scenario: A dog shelter would like a simple system to keep...
Using Java language (in program NetBeans). 1) Using a 2 dimensional array Your company has 4...
Using Java language (in program NetBeans). 1) Using a 2 dimensional array Your company has 4 grocery stores. Each store has 3 departments where product presentation affects sales (produce, meat, frozen). Every so often a department in a store gets a bonus for doing a really good job. You need to create a program that keeps a table of bonuses in the system for departments. Create a program that has a two dimensional array for these bonuses. The stores can...
{Continuation of Previous Question} Bond J is a 3 percent coupon bond. Bond K is a...
{Continuation of Previous Question} Bond J is a 3 percent coupon bond. Bond K is a 9 percent coupon bond. Both bonds have 7 years to maturity, make semiannual payments, and have a YTM of 6 percent. If interest rates suddenly rise by 5 percent, Bond K will decrease in price by ……………………. percent (enter 5.5% as 5.5 not 0.055, min 2 decimal accuracy)
CS 206 Visual Programming, Netbeans Problem: Write a Java program that displays all the leap years,...
CS 206 Visual Programming, Netbeans Problem: Write a Java program that displays all the leap years, 10 per line, from 1001 to 2100, separated by exactly one space. Also display the total number of leap years in this period. Hints: you need to use a loop ( for-loop is more suitable)
Note: this is my second time submitting this question. Previous answer for cost of equity percentage...
Note: this is my second time submitting this question. Previous answer for cost of equity percentage (10.19%) and WACC (7.54%) were wrong. please try to do again.   cost of debt of 5.52% is correct. Thank you, ----------------------------------------------------------------------------- If Wild Widgets, Inc., were an all-equity company, it would have a beta of .90. The company has a target debt-equity ratio of .45. The expected return on the market portfolio is 11 percent and Treasury bills currently yield 2.9 percent. The company...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT