Question

HW7: Feature Comparison CSS 142 Computer Programming 1 By: Hansel Ong Summary With so many options for most anything nowadaysClass Design: Device The Device class is intended to be an abstract and simplified representation of a device. Each device wiClass Design: Driver Positive testing (checking for valid conditions) o [1 Point] Create a Device with only device name o

In Java PLS

HW7: Feature Comparison CSS 142 Computer Programming 1 By: Hansel Ong Summary With so many options for most anything nowadays (phones, cars, hotels, schools, courses, etc.) consumers have become accustomed to selecting a few objects (e.g. smart watches) to compare the features. Write a simple "Device" class with a few features that could be used to compare Device instances and a Driver class with which to test/drive this "Device" class. Skills Expected All the skills from previous assignment(s) Multi-dimensional array . Constructor and method overloading Assignment Description (and grading criteria) You will create two Class objects (and subsequently submit two.java files) Device Driver Notes: ONLY the Driver Class should have static methods. . The Device Class should NOT have static methods. The Device Class should NOT have static instance variables (Constants permitted). . The below is the minimum you must include-you could include additional instance variables, methods, etc. as you need.
Class Design: Device The Device class is intended to be an abstract and simplified representation of a device. Each device will have a multi-dimensional array of "features" - which contain the feature name (e.g. "Storage Size") in one row and the feature data (e.g. "64GB" in another rovw Data to Store (2 Points) Device Name private instance variable with public setter/getter · (2 Points) Features List (eg. String[][]) → private instance array with neither getter nor setter Actions Constructor (1 Point) Take in as argument the device name (enforce invariants) (1 Point) Initialize the features list to have at least 10 columns and 2 rows o o Overloaded Constructor o (2 Points) Take in as argument the device name as well as features list (enforce invariants) (2 Points) Add Feature o Take in as argument the feature name and value and o If the feature name is NOT already in the list of features, add both the name and value to the list of features If the feature name is already in the list of features, update the value to include the previous value as well as the new valuee o (2 Points) Get Feature Value o Take in as argument a feature name and return the value associated with the feature if round. Return “Feature not found" as appropriate (2 Points) Get Feature Value o Take in as argument an index value and return the value associated with feature for the given index. Be sure to check for invariants. (2 Points) Show Features Print out a "table" of features for the current Device instance o
Class Design: Driver "Positive" testing (checking for "valid" conditions) o [1 Point] Create a Device with only device name o [1 Point] Create a Device with both a device name as well as a feature list o [1 Point] Add at least three new features (with different values) to all device instances o [1 Point] Get a feature value based on the feature name o [1 Point] Get a feature value based on the index o [1 Point] Print out the list of features "Negative" testing (checking for "invalid" conditions) o [1 Point] Attempt to create a Device with "invalid" device name (e.g. empty string) o [1 Point] Attempt to create a Device with "invalid device name and/or feature list o [1 Point] Attempt to add a feature that has already been added to the feature list o [1 Point] Attempt to get the value for a feature not in the feature list o [1 Point] Attempt to get the value for a feature given an invalid index (e.g. -1) . "Boundary" testing o [1 Point] Attempt to create a Device with a feature list that is exactly at capacity o [1 Point] Attempt to create a Device with a feature list that exceeds capacity (e.g. 11 columns) o [1 Point] Attempt to add a feature with invalid name/value o [1 Point] Attempt to show features when the feature list has nothing in it yet Grading Criteria [12 Points] Device class (See Assignment Description for breakdown of points) [15 Points] Driver class (See Assignment Description for breakdown of points) [1 Points] Method JavaDoc (comment block) containing at minimum: description of method and @param and @return [1 Point] Descriptive variable names . [1 Point] Appropriate class header comment block
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Thanks for the question.
Here is the completed code for this problem. Let me know if you have any doubts or if you need anything to change.
Thank You !!
================================================================================================

public class Device {

    private String deviceName;
    private String[][] features;
    private int featureCount;

    public Device(String deviceName) {
        setDeviceName(deviceName);
        features = new String[2][10];
        featureCount = 0;
    }

    public String getDeviceName() {
        return deviceName;
    }

    public void setDeviceName(String deviceName) {
        if (deviceName == null || deviceName.trim().length() == 0) {
            throw new IllegalArgumentException("Device Name cannot be null or empty");
        }
        this.deviceName = deviceName;
    }

    public void addFeature(String featureName, String featureValue) {
        if (featureName == null || featureName.trim().length() == 0) {
            System.out.println("Invalid feature name.");
            return;
        }
        if (featureCount < 10) {
            // check if the feature exists
            for (int col = 0; col < featureCount; col++) {
                if (features[0][col].equalsIgnoreCase(featureName)) {
                    features[1][featureCount] = featureName;
                    return;
                }
            }
            // if feature dont exist add a new entry
            features[0][featureCount] = featureName;
            features[1][featureCount] = featureValue;
            featureCount += 1;
        }
    }

    public String getFeatureValue(String featureName) {
        if (featureName == null || featureName.trim().length() == 0) {
            System.out.println("Invalid feature name.");
            return "Feature not found";
        }
        for (int col = 0; col < featureCount; col++) {
            if (features[0][col].equals(featureName)) {
                return features[1][col];
            }
        }
        return "Feature not found";
    }

    public String getFeatureValue(int index) {
        if (index < 1 || index > featureCount) {
            return "Feature not found";
        }
        return features[1][index - 1];
    }

    public void showFeatures() {

        System.out.println("Device Name: " + getDeviceName());
        if (featureCount == 0) {
            System.out.println("No Feature exist.");
            return;

        }

        System.out.println(String.format("%-15s%15s", "Feature Name", "Feature Value"));
        for (int col = 0; col < featureCount; col++) {
            System.out.println(String.format("%-15s%15s", features[0][col], features[1][col]));
        }

    }
}

================================================================================================

public class DeviceDriver {

    public static void main(String[] args) {

        Device dell = new Device("Dell");
        Device hp = new Device("HP");
        hp.addFeature("RAM","8GB");
        hp.addFeature("Hard Disk","1024 GB");
        hp.addFeature("Processor","Quad Core");
        System.out.println("HP Hard Disk Value: "+hp.getFeatureValue("Hard Disk"));
        System.out.println("HP Feature at index 3: "+hp.getFeatureValue(3));
        hp.showFeatures();

        try{
            Device lenevo = new Device("");
        }catch (IllegalArgumentException exception){
            System.out.println(exception.getMessage());
        }

        // feature all exist
        hp.addFeature("RAM","16GB");
        System.out.println("HP RAM Value: "+hp.getFeatureValue("RAM"));
        // feaure dont exist
        System.out.println("HP Operating System Value: "+hp.getFeatureValue("OS"));
        // negative index -1
        System.out.println("HP Feature at index -1: "+hp.getFeatureValue(-1));
        // boundary
        hp.addFeature("Feature 4","Feature Value 4");
        hp.addFeature("Feature 5","Feature Value 5");
        hp.addFeature("Feature 6","Feature Value 6");
        hp.addFeature("Feature 7","Feature Value 7");
        hp.addFeature("Feature 8","Feature Value 8");
        hp.addFeature("Feature 9","Feature Value 9");
        hp.addFeature("Feature 10","Feature Value 10");
        hp.showFeatures();
        // one more feature
        hp.addFeature("Feature 11","Feature Value 11");
        hp.showFeatures();

        // negative testing
        hp.addFeature(null,"Null Value");
        dell.showFeatures();



    }
}

================================================================================================

DeviceDriver un: C:\Program Files Java\jdk-11kbin\java.exe -javaagent:C:\Prog HP Hard Disk Value: 1024 GB HP Feature at in

DeviceDriver Run: vice Name cannot pe null or empty T HP RAM Value: 8GB HP Operating System Value: Feature not found HP Featu

thanks !

> 3 inter-dependent invariants are missing
Overloaded Constructor is also missing.

Huyen Nguyen Sun, Nov 28, 2021 6:02 PM

Add a comment
Know the answer?
Add Answer to:
In Java PLS HW7: Feature Comparison CSS 142 Computer Programming 1 By: Hansel Ong Summary With so many options for most...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • USING JAVA, Class Design: Person The Person class is intended to be an abstract and simplified representation of a pers...

    USING JAVA, Class Design: Person The Person class is intended to be an abstract and simplified representation of a person. Each person will have an array of "friends" - which are other "Person" instances. Data to Store (2 Points) Name private instance variable with only private setter (2 Points) Friends private instance array with neither getter nor setter Actions Constructor o 1 Point) Take in as argument the name of the person (enforce invariants) o (1 Point) Initialize the array...

  • In Java Pls Class Design: Donut (Suggested Time Spent: < 15 minutes) The Donut class is intended to be an abstract a...

    In Java Pls Class Design: Donut (Suggested Time Spent: < 15 minutes) The Donut class is intended to be an abstract and simplified representation of a yummy edible donut Class Properties (MUST be private) Name of the donut Type of donut Price of the donut Class Invariants Donut name must not be empty (Default: "Classic") Type of donut can only be one of the following: "Plain," "Filled," or "Glazed" (Default: "Plain") Class Components Public Getter and Private Setter for name,...

  • In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program...

    In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program to create a database of dogs of your own. You will also include File I/O with this program. You will create 3 classes for this assignment. The first class: Create a Class representing the information that is associated with one item (one dog) of your database. Name this class Dog. Using Lab 3, this will include the information in regard to one dog. The...

  • Java Object Array With 2 Elements In 1 Object

    1. Create a UML diagram to help design the class described in Q2 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Person class object; should they be private or public? Determine what class methods are required; should they be private or public?2. Write Java code for a Person class. A Person has a name of type String and an age of type integer.Supply two constructors: one will be...

  • Course, Schedule, and ScheduleTester (100%) Write a JAVA program that meets the following requirements: Course Class Cr...

    Course, Schedule, and ScheduleTester (100%) Write a JAVA program that meets the following requirements: Course Class Create a class called Course. It will not have a main method; it is a business class. Put in your documentation comments at the top. Be sure to include your name. Course must have the following instance variables named as shown in the table: Variable name Description crn A unique number given each semester to a section (stands for Course Registration Number) subject A...

  • Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   and please put comment with code! Problem:2 1. Class Student Create...

    Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   and please put comment with code! Problem:2 1. Class Student Create a "Hello C++! I love CS52" Program 10 points Create a program that simply outputs the text Hello C++!I love CS52" when you run it. This can be done by using cout object in the main function. 2. Create a Class and an Object In the same file as...

  • The following is for java programming. the classes money date and array list are so I are are pre...

    The following is for java programming. the classes money date and array list are so I are are pre made to help with the coding so you can resuse them where applicable Question 3. (10 marks) Here are three incomplete Java classes that model students, staff, and faculty members at a university class Student [ private String lastName; private String firstName; private Address address; private String degreeProgram; private IDNumber studentNumber; // Constructors and methods omitted. class Staff private String lastName;...

  • MasterMind in Java Activity MasterMind project Create a new Java Application project named MasterMind allowing Netbeans...

    MasterMind in Java Activity MasterMind project Create a new Java Application project named MasterMind allowing Netbeans IDE to create the main class called MasterMind.java MasterMind class Method main() should: Call static method System.out.println() and result in displaying “Welcome to MasterMind!” Call static method JOptionPane.showMessageDialog(arg1, arg2) and result in displaying a message dialog displaying “Let’s Play MasterMind!” Instantiate an instance of class Game() constants Create package Constants class Create class Constants Create constants by declaring them as “public static final”: public...

  • signature 1. Create a new NetBeans Java project. The name of the project has to be...

    signature 1. Create a new NetBeans Java project. The name of the project has to be the first part of the name you write on the test sheet. The name of the package has to be testo You can chose a name for the Main class. (2p) 2. Create a new class named Address in the test Two package. This class has the following attributes: city: String-the name of the city zip: int - the ZIP code of the city...

  • Amusement Park Programming Project Project Outcomes Use the Java selection constructs (if and if else). Use...

    Amusement Park Programming Project Project Outcomes Use the Java selection constructs (if and if else). Use the Java iteration constructs (while, do, for). Use Boolean variables and expressions to control iterations. Use arrays or ArrayList for storing objects. Proper design techniques. Project Requirements Your job is to implement a simple amusement park information system that keeps track of admission tickets and merchandise in the gift shop. The information system consists of three classes including a class to model tickets, a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT