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

BCS 345 Exam 2 CRN 21177, XXXXXXXXXXJLi Spring 2020 ------------------------------------------------------------------------------------------------------------------------ Instructions: This is a...

2 answer below »
BCS 345 Exam 2
CRN 21177, XXXXXXXXXXJLi Spring 2020
------------------------------------------------------------------------------------------------------------------------
Instructions: This is a programming exam and requires file submission. You can refer to lecture slides, your previous
labs, homework assignments, and class demo programs. You can use NetBeans or other IDEs to write, compile, run,
and test your program. You must complete the exam independently.
Be sure to include the integrity statement I certify that this submission is my own original work with
your name and RAM ID in all your source files.
Tasks:
Create a NetBeans project called BCS345Exam2. Add a new Java class Television to the project. Use the
default package for your project.

1. Define the Television class as follows. Each object that is created from the Television class must be able
to hold information about that instance of a Television in its fields. So, a Television class will have the
following private fields:
No. Fields Description
1
and The
and attribute will hold the
and name. This cannot change once the
television is created, so will be a named constant (use the final keyword).
2 screenSize The screenSize attribute will hold the size of the television screen. This cannot
change once the television has been created so will be a named constant.
3 powerOn The powerOn attribute will hold the value true if the power is on and false if
the power is off.
4 channel The channel attribute will hold the value of the station that the television is
showing.
5 volume The volume attribute will hold a number value representing the loudness (0 being
no sound).
The Television object will also be able to control the state of its attributes. These controls become methods in
the class. The Television class has the following public methods and has two constructors to create the instance
of the class.
No. Method Name Description
1 power The power method will toggle the power between on and off, changing the
value stored in the powerOn field from true to false or from false to
true.
2 getBrand The getBrand method will return the constant value stored in the
and
field.
3 getScreenSize The getScreenSize method will return the constant value stored in the
screenSize field.
4 getChannel The getChannel method will return the value stored in the channel field.
5 getVolume The getVolume method will return the value stored in the volume field.
6 setChannel The setChannel method will accept an int argument and use it to set the
channel. A valid value should be a positive integer. For an invalid value, set
the channel to 2.
7 increaseVolume The increaseVolume method will increase the value stored in the
volume field by 1.
8 decreaseVolume The decreaseVolume method will decrease the value stored in the
volume field by 1.
9 Constructor The constructor has two parameters, a string for
and and an int for screen
size. These parameters will
ing in information to initialize the
and and
screenSize fields. The constructor initializes the powerOn field to
false (power is off), the volume to 10, and the channel to 2.
10 toString The toString method will display on the screen the
and, screen size,
channel, volume, and powerOn status of a Television object.
11 Copy
Constructor
The constructor creates a Television object through copying the fields of an
existing Television object.
12 equals The equals method will compare two Television objects’
and name
and screen size, and return true if they are the same, otherwise return false.
2. In the BCS345Exam2.java program (the driver program or client program), write statements in the main
method to test your Television class.
Inside the main method,
1) Declare a Television object called livingroomTV and instantiate it to be a Samsung 50-inch
television.
2) Turn the power on.
3) Prompt the user for a channel and change the channel to the user’s input.
4) Decrease the volume by two.
5) Display the cu
ent channel and the volume of the television.
6) Display the cu
ent state of livingroomTV by calling the toString method.
7) Make another Television object diningroomTV and instantiate it to your preference.
8) Display the cu
ent state of diningroomTV.
9) Test the copy constructor.
10) Test the equals method.
3. Write a method printA
ay that accepts an a
ay of Television objects and prints their information on the
console. Remember to use the length field to get the size of the a
ay.
4. In the main method, create an a
ay of Television objects of size 4 and instantiate them with LG 40-inch, Sharp
36-inch, Sony 70-inch, and Samsung 65-inch. Call the printA
ay method to output the information of the
Television objects in the a
ay.
5. Create a data file exam2data.txt that includes the following data:
Toshiba
50
Philips
56
Panasonic
44
TCL
68
Visio
65
6. In the client program, create an a
ay of Television of size 10. Call the printA
ay method to output the
information of the Television objects in the whole a
ay.
7. Use a while loop to read data from the above file and instantiate the Television objects. Call the printA
ay
method to output the information of the Television objects in the whole a
ay.
Hint:
1. Use a while loop with hasNext() method to read a flexible number of items from a file.
2. When calling the nextLine method after nextInt method, to consume the newline character after the
integer, call nextLine() before normal reading operations, for example,
Toshiba
Call nextLine() to read a line
50
Call nextInt() to read an integer. The internal pointer stops right after the integer.

Call nextLine() one more time (but not use the value) to consume the newline character.
Repeat the above operations to read another Television object’s
and and screensize in the next iteration.
Submission:
Submit your two source code files in Blackboard. The file names are case-sensitive and must be
BCS345Exam2.java and Television.java. Use the default package for your project. Points
will be deducted for submission that doesn’t meet the name and package requirements.
Answered Same Day Apr 02, 2021 BCS345

Solution

Valupadasu answered on Apr 02 2021
159 Votes
public class Television {
    private final String
and;
    private final int screenSize;
    private boolean powerOn;
    private String channel;
    private int volume;
    
    public Television(String
and,int screenSize){
        this.
and =
and;
        this.screenSize = screenSize;
        
    }
    
    public Television(Television televison){
        this.
and = televison.
and;
        this.screenSize = televison.screenSize;
        this.powerOn = televison.powerOn;
        this.channel =...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here