Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Topic: Java Programming Hello, I am having difficulty in getting the correct code for the following problem - specifically for Task #4. Here is what

Topic: Java Programming

Hello,

I am having difficulty in getting the correct code for the following problem - specifically for Task #4.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Here is what i have for Task 4:

Beginning of code...

import java.util.Scanner;

public class TelevisionDemo { public static void main(String[] args) { //create a Scanner object to read from the keyboard Scanner keyboard = new Scanner (System.in);

//declare variables int station; //the user?s channel choice

//declare and instantiate a television object Television bigScreen = new Television("Toshiba", 55); //turn the power on bigScreen.power(); //display the state of the television System.out.println("A " + bigScreen.getScreenSize() + " inch " + bigScreen.getManufacturer() + " has been turned on."); //prompt the user for input and store into station System.out.print("What channel do you want? "); station = keyboard.nextInt();

//change the channel on the television bigScreen.setChannel(station); //increase the volume of the television bigScreen.increaseVolume(); //display the the current channel and volume of the television System.out.println("Channel: " + bigScreen.getChannel() + " Volume: " + bigScreen.getVolume()); System.out.println("Too loud!! I am lowering the volume."); //decrease the volume of the television bigScreen.decreaseVolume(); bigScreen.decreaseVolume(); bigScreen.decreaseVolume(); bigScreen.decreaseVolume(); bigScreen.decreaseVolume(); bigScreen.decreaseVolume(); //display the current channel and volume of the television System.out.println("Channel: " + bigScreen.getChannel() + " Volume: " + bigScreen.getVolume()); System.out.println(); //for a blank line

AutoSave A S 56: 2 Project 8 - Compatibility Mode - Saved to my Mac Home Insert Draw Design Layout References Mailings Review View Acrobat Times Now... 16 AA Ma A E M EAU A.S.COM. AaBbcc.ac.Dr. BU+xA 2.A EEEEE 8 Share Comments AaBhCD, USB Fwcip 1 Nauru No Scuciny Styles Dictate Sensitivity Create and Share Request Adobe PDF Sanatures Project 6 Classes and Objects Introduction Everyone is familiar with a television. It is the object we are going to create in this project. First we need a blueprint. All manufacturers buave the samne basic elements in the televisions they produce as well as many options. We are going to work with a few basic elements tbul are common to all televisions. Think ubout u television in general. It has a brand name (i.e. it is made by a specific manufacturer'). The television screen has a specific size. It has soune busic controls. There is a control to turn the power on and off. There is a control to change the channel. There is also a control for the volume. At any point in time, the television's state can be described by how these controls are set. We will write the television class. Each object that is created from the television class must be able to hold information about that instance of a television in fields. So a television object will have the following attributes: manufacturer. The manufacturer attribute will hold the brand name. This cannot change once the television is created, so will be a named constant. screepSize. The screen Size attribute will hold the size of the television screen This cannot change orxe the television has been created so will be a named constant. powerm. The powerOn attribute will hold the value true if the power is on, and false if the power is off. channel. The channel attribute will hold the value of the station that the television is showing volume The volume attribute will hold a number value representing the louiness (U being no sound). These attributes become fields in our class. The television object will alsu be able to control the state of its attributes. These controls become methods in our class. .setChaoncl. The setChannel method will store the desired station in the channel field. power. The power tebud will logule the power between unod oll, chunging the value stored in the power on field from true to false or from false to true. increase Volume. The incrcaseVolume mcthod will incrcase the value stored in the volume field by 1. duercaseVolume, The decreaseVolume method will decrease the value stored in the volume field by 1. gel Chiodel The Channel teod will return the value stored in the channel Geld. Page 106 212 words English (United States : 1 Focus F C = = - + 37% AutoSave A S 5o = Home Insert Draw Design Layout References Mailings Review View Times Now... 16 AAM A E BIU. x A 2-A EEEEE. 2 Project 8 - Compatibility Mode - Saved to my Mac Acrobat I HOME AaBbcc.CONF. A AaBhCAD Share Comments 2 Create and Share Request Adobe PDF Senatures No Scuciny Styles Dictate Sensitivity vtVolume. The vet Volume method will return the vulue stored in the volume field. Manufacturer The Manufacturer method will return the constant value stored in the MANUFACTURER field. getScreen Size. The getScreen Size method will return the constant value stored in the SCREEN_SIZE field. We will also need a constructor method that will be used to create an instance of a Television. These ideas can be brought together to form a UML (Unified Modeling Language) diuyrun for this class as shown below. Television Class Namc Attributes or fields -MANUFACTURER: String -SCREEN_SIZE: int -powerOn: boolcan cbnnel: inl -volume: int Television brand: Striny, size: int): +actChannel (station: int): void power: void tincrease Volume: void +decreuse Volume: void +getChannel in actVolumci: int +gel Memululuu : String +octScreen Size : int Methods + public - private Data type retumed Page 2 of 1312 vords English (United States) : 1 Focus F C = = - + 37% AutoSave A S 56: 2 Project 8 - Compatibility Mode - Saved to my Mac Home Insert Draw Design Layout References Mailings Review View Acrobat Times Now... 16 AA Ma A B E AU A.S.COM. AaBbcc.ac.Dr. BU+xA 2.A EEEEE 8 Share Comments AaBhCD, USB No Scuciny Styles Dictate Sensitivity Create and Share Request Adobe PDF Sanatures Task #1 Creating a New Class 1. In a new file, create a class definition called Television. 2. Put u program heuder (comments/documentation) at the top of the file // The purpose of this dass is to model a television // Your name and today's date 3. Declare the 2 constant fields listed in the UML diayrun. 4. Declare the 3 remaining fields listed in the UML diagram. 5. Write a comment for cach ticld indicating what it represents. 6. Save this Gile ils Television.java. 7. Compile and debug. Do not run. Task #2 Writing a Constructor 1. Create a constructor definition thut has two parameters, a manutucturer's brund and a screen size. These parameters will bring in information 2. Inside the constructor, assign the values taken in from the parameters to the wresponding Gelds. 3. Trulialize the power on field to false (power is of), the volume lo 20, and the channel to 2. 4. Wrile comments describing the purpose of the constructor above the metod header 5. Compile und debuy. Do not rum. Task #3 Methods 1. Define accessor methods called ger Volume, getChannel, get Manufacturer, and actScreen Size that return the value of the corresponding ticld. 2. Deline u mulailur method called Chinel acuepls a value to be stored in the channel ficld. Define a mutator method called power that changes the state from true to false or from false to true. This cun be uccomplished by using the NOT operator (!). If the boolean variable power is true, then ! power On is false and vice versa, Usc thc assignment statement DOWCION = rokorr, lo chunge the stule of poweron and then store it back into powerOn (rentember assignment statements evaluate the right hand side first, then assign the result to the left hand side variablc. 4. Deline Iwo mulalor methods to change the volume. One med should be called increase Vahame and will increase the volume by 1. The other method should be called decrease Volume und will decrease the volume by 1. 5. Write comments above each method header describing the purpose of the method. 6. Compile and debug. Do not run. Page 366 1312 vords English (United States) : 1 Focus F C = = - + 37% AutoSave A S 5o = Home Insert Draw Design Layout References Mailings Review View Times Now... 16 AAM A E BU+XA 2A EEEEE. 2 Project 8 - Compatibility Mode - Saved to my Mac Acrobat I HOME AaBbcc.CONF. A Share Comments AaBhCD, USB No Scuciny Styles Dictate Sensitivity Create and Share Request Adobe PDF Senatures Task #4 Running the application 1. You can only execute (run) u program that has a main method, so there is u driver program that is already written to test out your Television class. Copy the file Television Demojava (sce code listing 3.1). Make sure it is in the same directory as Television.java. 2. Compilc and run TelevisionDemo and follow the prompts. 3. If your output matches the output below, Television.java is complete and correct. You will not need to modify it further for this lab. OUTPUT (boldface is user input) A 55 inch Toshiba has been turnod on. Wbul channel do you want? 56 Channel: 56 Volume: 21 Too loud!! 1 an lowering the volume. Channel: 56 Volume: 15 Task #5 Creating another instance of a Television I. Edit the TelevisionDemo.java file. 2. Add to the comment header as indicated at the top of the program. 3. Declare another Television object called portable. 4. Instantiate portable to be a Sharp 19 inch telcvision. 5. Use a cull to the power method to turn the power on. 6. Use calls to the accessor methods to print what television was turned on. 7. Use calls to the mutator methods to change the chunnel to the user's preference and decrease the volume hy two. 8. Use calls to the accessor incthods to print the changed state of the portable. 9. Corupile and debug this class 10. Run TelevisionDemo again. 11. The output for tusk #5 will appear after the output from above, since we wckled onto the bottom of the program. The output for task #5 is shown below. OUTPUT (boldface is user input) A 19 inch Sharp has been turned on. What channel do you want? 7 Channel: 7 Volume: 18 Page 4 of 6 312 crd English United States : 1 Focus F C = = - + 37%

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions