Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Homework 3 Before attempting this project, be sure you have completed all of the reading assignments, hands-on labs, discussions, and assignments to date. Create a Java class named HeadPhone to...

1 answer below »
Homework 3
Before attempting this project, be sure you have completed all of the reading assignments, hands-on
labs, discussions, and assignments to date.
Create a Java class named HeadPhone to represent a headphone set. The class contains:
ï‚· Three constants named LOW, MEDIUM and HIGH with values of 1, 2 and 3 to denote the
headphone volume.
ï‚· A private int data field named volume that specifies the volume of the headphone. The
default volume is MEDIUM.
ï‚· A private boolean data field named pluggedIn that specifies if the headphone is plugged
in. The default value is false.
ï‚· A private String data field named manufacturer that specifies the name of the
manufacturer of the headphones.
ï‚· A private Color data field named headPhoneColor that specifies the color of the
headphones.
ï‚· A private String data field named headPhoneModel that specifies the Model of the
headphones.
ï‚· getter and setter methods for all data fields.
ï‚· A no argument constructor that creates a default headphone.
ï‚· A method named toString() that returns a string describing the cu
ent field values of
the headphones.
ï‚· A method named changeVolume(value) that changes the volume of the headphone to
the value passed into the method
Create a TestHeadPhone class that constructs at least 3 HeadPhone objects. For each of the objects
constructed, demonstrate the use of each of the methods. Be sure to use your IDE to accomplish this
assignment.
The google recommended Java style guide, provided as link in the week 2 content, should be used to
format and document your code. Specifically, the following style guide attributes should be addressed:
ï‚· Header comments include filename, author, date and
ief purpose of the program.
ï‚· In-line comments used to describe major functionality of the code.
ï‚· Meaningful variable names and prompts applied.
ï‚· Class names are written in UpperCamelCase.
ï‚· Variable names are written in lowerCamelCase.
ï‚· Constant names are in written in All Capitals.
ï‚· Braces use K&R style.
Submission requirements
Deliverables include all Java files (.java) and a single word (or PDF) document. The Java files should be
named appropriately for your applications. The word (or PDF) document should include screen captures
showing the successful compiling and running of each of the test cases. Each screen capture should be
properly labeled clearly indicated what the screen capture represents. The test cases table should be
included in your word or PDF document and properly labeled as well.
Submit your files to the Homework 3 assignment area no later than the due date listed in your LEO
classroom. You should include your name and HW3 in your word (or PDF) file submitted (e.g.
firstnamelastnamehw3.docx or firstnamelastnamehw3.pdf)
Grading Ru
ic:
The following grading ru
ic will be used to determine your grade:
Attribute Meets Does not meet
Headphone Class 10 points
Three constants named LOW,
MEDIUM and HIGH with values
of 1, 2 and 3 to denote the
headphone volume
A private int data field named
volume that specifies the
volume of the headphone. The
default volume is MEDIUM.
A private boolean data field
named pluggedIn that specifies
if the headphone is plugged in.
The default value is false.
A private String data field
named manufacturer that
specifies the name of the
manufacturer of the
headphones.
A private Color data field named
headPhoneColor that specifies
the color of the headphones.
A private String data field
named headPhoneModel that
specifies the Model of the
headphones.
0 points
Three constants named LOW,
MEDIUM and HIGH with values
of 1, 2 and 3 were not included.
A private int data field named
volume was not included.
A private boolean data field
named pluggedIn was not
included.
A private String data field
named manufacturer was not
included
A private Color data field named
headPhoneColor was not
included.
A private String data field
named headPhoneModel was
not included
getter and setter methods for
all data fields were not
included.
A no argument constructor was
not included.
getter and setter methods for
all data fields.
A no argument constructor that
creates a default headphone.
A method named toString() that
eturns a string describing the
cu
ent field values of the
headphones.
A method named
changeVolume(value) that
changes the volume of the
headphone to the value passed
into the method
An IDE (Netbeans or Eclipse)
was used for this assignment.
A method named toString()was
not included.
A method named
changeVolume(value) was not
included.
An IDE (Netbeans or Eclipse)
was not used for this
assignment.
Test Headphone Class 5 points
TestHeadPhone class was used
to construct at least 3
HeadPhone objects.
For each of the objects
constructed, the use of each of
the methods was demonstrated
An IDE (Netbeans or Eclipse)
was used for this assignment.
0 points
TestHeadPhone class was not
used to construct at least 3
HeadPhone objects.
For each of the objects
constructed, the use of each of
the methods was not
demonstrated
An IDE (Netbeans or Eclipse)
was not used for this
assignment.
Test Cases 5 points
A minimum of 3 test cases was
used in the form of table with
columns indicating the input
values, expected output, actual
output and if the test case
passed or failed. The table
should contains 4 columns with
appropriate labels and a row for
each test case.
0 points
No test cases were provided.
Test cases were included in the
supporting word or PDF
documentation.
Documentation and Style guide 5 points
Screen captures were provided
and labeled for compiling your
code, and running each of your
3 test cases.
Header comments include
filename, author, date and
ief
purpose of the program.
In-line comments used to
describe major functionality of
the code.
Meaningful variable names and
prompts applied.
Class names are written in
UpperCamelCase.
Variable names are written in
lowerCamelCase.
Constant names are in written
in All Capitals.
Braces use K&R style.
0 points
No documentation included
Java style guide was not used to
prepare the Java code.
Answered Same Day Jul 20, 2021

Solution

Mohd answered on Jul 23 2021
137 Votes
Solution/Document.docx
                Homework 3
HeadPhone.java
**
* FileName: HeadPhone.java
* Author Name:
* Date: 22'July'2019
* Description: In this HeadPhone class, define specific property and method of HeadPhone,
*
import java.awt.Color;
public class HeadPhone {
    
define constant fields for volume
    public static final int LOW = 1;
    public static final int MEDIUM = 2;
    public static final int HIGH = 3;
    
    
define private fields
    private int volume = MEDIUM;
    private boolean pluggedIn = false;
    private String manufacturer;
    private Color headPhoneColor;
    private String headPhoneModel;
    
    
default constructo
    public HeadPhone()
    {}
    
    
getter method of Volume field
    public int getVolume() {
        return volume;
    }
    
setter method of Volume field
    public void setVolume(int volume) {
        this.volume = volume;
    }
    
    
getter method of pluggedIn field
    public boolean isPluggedIn() {
        return pluggedIn;
    }
    
setter method of pluggedIn field
    public void setPluggedIn(boolean pluggedIn) {
        this.pluggedIn = pluggedIn;
    }
    
    
getter method of manufacturer field
    public String getManufacturer() {
        return manufacturer;
    }
    
setter method of manufacturer field
    public void setManufacturer(String manufacturer) {
        this.manufacturer = manufacturer;
    }
    
    
getter method of headPhoneColor field
    public Color getHeadPhoneColor() {
        return headPhoneColor;
    }
    
setter method of headPhoneColor field
    public void setHeadPhoneColor(Color headPhoneColor) {
        this.headPhoneColor = headPhoneColor;
    }
    
    
getter method of headPhoneModel field
    public String getHeadPhoneModel() {
        return headPhoneModel;
    }
    
setter method of headPhoneModel field
    public void setHeadPhoneModel(String headPhoneModel) {
        this.headPhoneModel = headPhoneModel;
    }
    
String representation of HeadPhone class
    @Ove
ide
    public String toString() {
        return "HeadPhone Details:- \nVolume: " + volume + "\nPluggedIn: " + pluggedIn + "\nManufacturer: " + manufacture
                + "\nHeadPhoneColor: " + headPhoneColor + "\nHeadPhoneModel: " + headPhoneModel;
    }
    
    
this method manage volume field
    public void changeVolume(int volume)
    {
        this.volume = volume;
    }
}
TestHeadPhone.java
**
* FileName: TestHeadPhone.java
* Author Name:
* Date: 22'July'2019
* Description: In this TestHeadPhone class, create 3 object of HeadPhone class, and set its property,
* then display it by using toString method
*
import java.awt.Color;
public class TestHeadPhone {
    
main program start here
    public static void main(String[] args)
    {
        
        
Create Object of HeadPhone class
        HeadPhone headPhone1 = new HeadPhone();
        
setter private fields by calling its setter method
        headPhone1.setVolume(HeadPhone.MEDIUM);
        headPhone1.setPluggedIn(true);
        headPhone1.setHeadPhoneColor(Color.RED);
        headPhone1.setManufacturer("X Company");
        headPhone1.setHeadPhoneModel("X1 Model");
        
        
Create Object of HeadPhone class
        HeadPhone headPhone2 = new HeadPhone();
        
setter private fields by calling its setter method
        headPhone2.setVolume(HeadPhone.LOW);
        headPhone2.setPluggedIn(false);
        headPhone2.setHeadPhoneColor(Color.BLUE);
        headPhone2.setManufacturer("Y Company");
        headPhone2.setHeadPhoneModel("Y1 Model");
        
        
Create Object of HeadPhone class
        HeadPhone headPhone3 = new HeadPhone();
        
setter private fields by calling its setter method
        headPhone3.setVolume(HeadPhone.HIGH);
        headPhone3.setPluggedIn(true);
        headPhone3.setHeadPhoneColor(Color.GREEN);
        headPhone3.setManufacturer("Z Company");
        headPhone3.setHeadPhoneModel("Z1 Model");
        
        
display 1 HeadPhone class object by using toString() method
        System.out.println(headPhone1.toString());
        System.out.println("====================\n");
        
display 2 HeadPhone class object
        System.out.println(headPhone2.toString());
        System.out.println("====================\n");
        
display 3 HeadPhone class object
        System.out.println(headPhone3.toString());
        System.out.println("====================\n");
    }
}
TestCase.java
**
* FileName: TestCase.java
* Author Name:
* Date: 22'July'2019
* Description: In this TestCase class, test HeadPhone class method,
*
import static org.junit.Assert.*;
import org.junit.Test;
public class TestCase {
    
test getVolume method
    @Test
    public void testGetVolume() {
        HeadPhone headPhone = new HeadPhone();
        int expected = headPhone.getVolume();
        int actual = 2;
        assertEquals(expected, actual);
        
    }
    
    
test isPluggedIn method
    @Test
    public void testIsPluggedIn() {
        
        HeadPhone headPhone = new HeadPhone();
        boolean expected = headPhone.isPluggedIn();
        boolean actual = false;
        assertEquals(expected, actual);
    }
    
    
test toString method
    @Test
    public void testToString() {
        HeadPhone headPhone = new HeadPhone();
        String expected = headPhone.toString();
        String actual = "HeadPhone Details:- \nVolume: " + 2 + "\nPluggedIn: " + false + "\nManufacturer: " + null
                + "\nHeadPhoneColor: " + null + "\nHeadPhoneModel: " + null;
        assertEquals(expected, actual);
    }
    
}
Screenshot of Output:
Test Case Table:
        Input Value
        Expected Value
        Actual Value
        Result
        Default value(getVolume() method)
        2
        2
        Passed
        Default value (getIsPluggedIn() method )
        False
        False
        Passed
        Deafault value ( toString() method )
        HeadPhone Details:-
Volume: 2
PluggedIn: false
Manufacturer: null
HeadPhoneColor: null
HeadPhoneModel: null
        HeadPhone Details:-
Volume: 2
PluggedIn: false
Manufacturer: null
HeadPhoneColor: null
HeadPhoneModel: null
        Passed
Test Case Screenshot:
Solution/Homework 3/.classpath

    
    
    
    
Solution/Homework 3/.project

     Homework 3
    
    
    
    
        
             org.eclipse.jdt.core.javabuilde
            
            
        
    
    
         org.eclipse.jdt.core.javanature
    
Solution/Homework 3/.settings/org.eclipse.jdt.core.prefs
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=e
o
org.eclipse.jdt.core.compiler.problem.enumIdentifier=e
o
org.eclipse.jdt.core.compiler.source=1.8
Solution/Homework 3
in/HeadPhone.class
public synchronized class HeadPhone {
public static final int LOW = 1;
public static final int MEDIUM = 2;
public static final int HIGH = 3;
private int volume;
private boolean pluggedIn;
private String manufacturer;
private java.awt.Color headPhoneColor;
private String headPhoneModel;
public void HeadPhone();
public int getVolume();
public void setVolume(int);
public boolean isPluggedIn();
public void setPluggedIn(boolean);
public String getManufacturer();
public void setManufacturer(String);
public java.awt.Color getHeadPhoneColor();
public void setHeadPhoneColor(java.awt.Color);
public String getHeadPhoneModel();
public void setHeadPhoneModel(String);
public String toString();
public void changeVolume(int);
}
Solution/Homework 3
in/TestCase.class
public synchronized class TestCase {
public void TestCase();
public void testGetVolume();
public void testIsPluggedIn();
public void testToString();
}
Solution/Homework 3
in/TestHeadPhone.class
public synchronized class TestHeadPhone {
public void TestHeadPhone();
public static void main(String[]);
}
Solution/Homework 3/doc/allclasses-frame.html
All Classes
        HeadPhone
TestCase
TestHeadPhone
Solution/Homework 3/doc/allclasses-noframe.html
All Classes
        HeadPhone
TestCase
TestHeadPhone
Solution/Homework 3/doc/class-use/HeadPhone.html
        
         Package          Class           Use          Tree          Deprecated          Index          Help 
        
        
 PREV 
 NEXT        
FRAMES  
 NO FRAMES  
 
All Classes
Uses of Class
HeadPhone
No usage of HeadPhone
        
         Package          Class           Use          Tree          Deprecated          Index          Help 
        
        
 PREV 
 NEXT        
FRAMES  
 NO FRAMES  
 
All Classes
Solution/Homework 3/doc/class-use/TestCase.html
        
         Package          Class           Use          Tree          Deprecated          Index          Help 
        
        
 PREV 
 NEXT        
FRAMES  
 NO FRAMES  
 
All Classes
Uses of Class
TestCase
No usage of TestCase
        
         Package          Class           Use          Tree          Deprecated          Index          Help 
        
        
 PREV 
 NEXT        
FRAMES  
 NO FRAMES  
 
All Classes
Solution/Homework 3/doc/class-use/TestHeadPhone.html
        
         Package          Class           Use          Tree          Deprecated          Index          Help 
        
        
 PREV 
 NEXT        
FRAMES  
 NO FRAMES  
 
All Classes
Uses of Class
TestHeadPhone
No usage of TestHeadPhone
        
         Package          Class           Use          Tree          Deprecated          Index          Help 
        
        
 PREV 
 NEXT        
FRAMES  
 NO FRAMES  
 
All Classes
Solution/Homework 3/doc/constant-values.html
        
         Package          Class          Use          Tree          Deprecated          Index          Help 
        
        
 PREV 
 NEXT        
FRAMES  
 NO FRAMES  
 
All Classes
Constant Field Values
Contents                
Unnamed>.*
        HeadPhone
        
public static final int        HIGH        3
        
public static final int        LOW        1
        
public static final int        MEDIUM        2
        
         Package          Class          Use          Tree          Deprecated          Index          Help 
        
        
 PREV 
 NEXT        
FRAMES  
 NO FRAMES  
 
All Classes
Solution/Homework 3/doc/deprecated-list.html
        
         Package          Class          Use          Tree           Deprecated          Index          Help 
        
        
 PREV 
 NEXT        
FRAMES  
 NO FRAMES  
 
All Classes
Deprecated API
Contents
        
         Package          Class          Use          Tree           Deprecated          ...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here