EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 4, Problem 9RQ
Program Description Answer
A constructor “can receive” parameters.
Hence, the correct option is “A”.
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
You are required to build a mini FunTime application for the kids to play with their electronic toys in a virtual world. Follow the given steps
Build a class Toy having the following data members
Name(String)
Color (String)
Type (String)
Price (float)
batteryHealth (int)
Provide constructor with arguments for name, color, type, and price. Initialize batteryHealth to 5 (which means full).
Provide getter for each of these but no setters.Provide a function charge(String time). This function would increase the batteryHealth of the toy according to following rules
Time
Increase in battery health
15 mins
20% charging (Increase health by 1)
30 mins
40%
45 mins
60%
1 hour
80%
1 hour 15 mins
100%
If the toy is already fully charged, then no more charging should be done and appropriate message to be displayed. The charge function returns the new health of the battery of toy object.
Provide another function play() that reduces the batteryHealth of the toy…
Create a constructor named Exam that assigns "Good luck" to a previously declared String variable named
Consider the code and output below. Is Car more likely to be a struct or a class?
func test(prototype: Car) -> String { prototype.speed = 100 // Assume that speed is an Int variable prototype.saveDiagnostics() // Assume saveDiagnostics stores information about changes to the car state prototype.speed = 120 prototype.saveDiagnostics() prototype.speed = 200 prototype.saveDiagnostics()return prototype.GetDiagnostics() // Assume GetDiagnostics returns a diagnostics report}var myCar = Car(speed: 0)print("Speed before testing: \(myCar.speed)")var result = test(prototype: myCar)print("Speed after testing: \(myCar.speed)")
Screen output:
Speed before testing: 0Speed after testing: 0
1. Car is a class
2. Car is a struct
3. Car is neither a class nor a struct
Chapter 4 Solutions
EBK JAVA PROGRAMMING
Ch. 4 - Prob. 1RQCh. 4 - Prob. 2RQCh. 4 - Prob. 3RQCh. 4 - Prob. 4RQCh. 4 - Prob. 5RQCh. 4 - Prob. 6RQCh. 4 - Prob. 7RQCh. 4 - Prob. 8RQCh. 4 - Prob. 9RQCh. 4 - Prob. 10RQ
Ch. 4 - Prob. 11RQCh. 4 - Prob. 12RQCh. 4 - Prob. 13RQCh. 4 - Prob. 14RQCh. 4 - Prob. 15RQCh. 4 - Prob. 16RQCh. 4 - Prob. 17RQCh. 4 - Prob. 18RQCh. 4 - Prob. 19RQCh. 4 - Prob. 20RQCh. 4 - Prob. 1PECh. 4 - Prob. 2PECh. 4 - Prob. 3PECh. 4 - Prob. 4PECh. 4 - Prob. 5PECh. 4 - Prob. 6PECh. 4 - Prob. 7PECh. 4 - Prob. 8PECh. 4 - Prob. 9PECh. 4 - Prob. 10PECh. 4 - Prob. 11PECh. 4 - Prob. 1GZCh. 4 - Prob. 2GZ
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Hello, I need help with this: – AssignmentFollowing on the success of homework 2, your mother wants you to augment the tag sale price trackingprogram. In addition to storing the price of each item sold, she wants to store the name of the item sold.Create a class called TagSaleItem, with the following variables (properties) and Get/Set members(functions)Double itemPriceString itemNameAdd a textbox to your form to input the name of the item at the same time as the price.The previous program used an array to store a list of prices. It would be awesome if this program usedan array of objects to store a list of items… but we’ll get to that in a later assignment. For now theassignment is just to create a class and a single object and demonstrate how to use it (using the Get/Setmethods) Code for homework 2 that is referenced: Imports System.IO Public Class FrmMain Dim prices(0) As Double ' Array to store prices of items sold Dim totalSales As Double ' Total amount of money collected…arrow_forwardYou have a base class called Shape such as: #include #include using namespace std; class Shape { protected: int sidel, side2; public: Shape (int a, int b) { sidel = a, side2 = b; } void set_values (int a, int b){ sidel = a; side2 - b;} }; Solve the following items: 1- Derive the Rectangle and Square classes from base class. 2- Calculate area for each one. 3- Display all results using virtual function called showResults(). 4- What is the type of the inheritance used in the program. 5- Test all the functions in your program by implementing them. Hint: - Add any functions or data you need that are suitable for your code.arrow_forwardJava Code please Input The first line contains an integer which is either 1 or 2. If it is a 1, it means to create a Date via the default constructor. If it is a 2, 3 integers follow in the next line representing the day, month, and year of the Date to be created. This is then followed by a number m representing the number of operations to be performed followed by the operations themselves as specified below: 1 - setDay 2 - setMonth 3 - setYear 4 - setDate 5 - getDay 6 - getMonth 7 - getYear 8 - toString 9 - dayOfTheWeek For operations 1, 2, 3, one integer follows. For setDate, 3 integers follow (D M Y). For the rest of the operations, no other inputs follow. 1 7 8 9 1·20 2·8 3·1980 8 9 Output The default Constructor should output "Default Constructor", and the overloaded constructor should output "Overloaded Constructor". All the setter operations will not output anything. For the getter operations (5 - 7), the values they return must be printed. Operations 8 and 9 should print…arrow_forward
- (a) Write the cinema class that contains two private data: one to hold cinema location and the other to hold the number of seats in cinema. (b) Write the constructor foe the class that takes two parameters to set the location and the number of seats.arrow_forwardcreate a class called tour.h it is for a company that gives tours of cities like Boston the following are the variables for this class that customers may choose: the durations of a tour are one and two hours the type of vehicles are bus and boat the daily times that tours begin are 10 am, 12 noon, and 2 pm there are four tour guides (one of them is you! and one of them is me! choose the other two (friends or family) include two constructors: one will be the default and will initialize each variable to a zero or "" the other constructor will pass arguments for each variable and assign them accordingly include your mutator and accessor functions for your tour.cpp file: display a greeting to potential customers, with your name as part of the company's name display a menu of choices for each variable, in the same order as the constructor throw exceptions for input errors after all user choices have been made, display everything in a confirmation report, like this: Duration: 2…arrow_forward!!!FIRST READ EVERYTHING WRITTEN BELOW AND IF YOU CAN DO IT ONLY THEN START AND NO PLAGIARISM!!! Only use C++ to do this task. And I will only give thumbs up if you do not plagiarize from another Chegg or internet source. Also only if you will follow all the below instructions 100%. Only write typed answer. No handwritten. Code must visibly shows the functions and class. Attach the screenshot of output and code must be 100% complete and correct. Write a Twitter class that sets the Twitter user first (who is to be followed) and lets the client add up to 5 followers, which will be stored in an array with a capacity of 5. These users/followers could be in the form of string or Profile but both must be of same type. (Note that the followers are not stored as users, but as strings or Profiles). At any time, your main program should be able to remove any user, x from following another user, y (i.e., x is no longer in the array of followers of y). You are free to design your program as you…arrow_forward
- **please see question attached** (previous program below) #include <iostream>using namespace std;class House{//instance variablesprivate:string location;int price; public://constructorsHouse(){location = "TBD";price = 0;}House(string location,int price){this->location = location;this->price = price;}//Get and set methodsvoid setLocation(string location){this->location = location;}string getLocation(){return location;}void setPrice(int price){this->price = price;}int getPrice(){return price;} };//member functionvoid output(House a){cout <<"Location: " << a.getLocation()<<endl;cout <<"Price: "<<a.getPrice()<<endl;}int main(){House a("1234 qcc st, Bayside, NY",1000000);output(a);House b;output(b); return 0;}arrow_forwarda. Create a class named Pizza. Data fields include a String for toppings (such as “pepperoni”), an integer for diameter in inches (such as 18), and a double for the price (such as P699.00). Include methods to get and set values for each of these fields. Save the class as Pizza.java. b. Create an application named TestPizza that instantiates one Pizza object and demonstrates the use of the Pizza set and get methods. Save this application as TestPizza.java.arrow_forwardCreate a constructor for the Student class you created. The constructor should initialize each Student’s ID number to 9999, his or her points earned to 12, and credit hours to 3 (resulting in a grade point average of 4.0). Write a program that demonstrates that the constructor works by instantiating an object and displaying the initial values. Save the application as ShowStudent2.java.arrow_forward
- Create a class named Package with data fields for weight in ounces, shipping method, and shipping cost. The shipping method is a character: A for air, T for truck, or M for mail. The Package class contains a constructor that requires arguments for weight and shipping method. The constructor calls a calculateCost() method that determines the shipping cost, based on the following table: Weight (oz.) Air ($) Truck ($) Mail ($) 1 to 8 9 to 16 17 and over 2.00 3.00 4.50 1.50 2.35 3.25 .50 1.50 2.15 The package class also contains a display() method that displays the values in all four fields. Create a subclass named InsuredPackage that adds an insurance cost to the shipping cost, based on the following table: Shipping Cost Before Insurance ($) Additional Cost ($) 0 to 1.00 1.01 to 3.00 3.01 and over 2.45 3.95 5.55 Write an application named UsePackage that instantiates at least three objects of each type (Package and InsuredPackage) using a variety of…arrow_forwardWRITE PLEASEJAVA write grading program for a class with the following grading policies. thers a total of 2 quizzes, each graded on the basis of 10 points. theeres is 1 midterm exam and one final exam, each graded on the basis of 100 points. final exam counts for 50% of the grade, the midterm counts for 25%, and the 2 quizzes together count for a total of 25%. (Do not forget to normalize the quiz scores.) letter grade will be given based on the following criterion: 90 – 100 A 80 – 89 B 70 – 79 C 60 – 69 D 0 – 59 E program will read student’s scores from a txf file, save them in an arrayor arrays), process the arrays), print the student’s record, which consists of the name, 2 quiz and 2 exam scores as well along with students avg numscore for the course and final letter rade. please noteAll the scores are integers and a student name consists of no more than 10 characters. justify output filearrow_forwardGiven the C++ statements as below: #include <iostream> using namespace std; const PI = 3.142; class Cone{ private: double radius; double height; public: Cone(){ // default constructor radius = 0; height = 0; cout << "Default constructor created !" << endl; } Cone(double radius, double height){ // overloaded constructor radius = radius; height = height; cout << "Overloaded constructor created !" << endl; } ~Cone(){ // destructor cout << "Object destroyed !" << endl; } double getRadius(){return radius;} double getHeight(){return height;} double calVolume(){ return (1.0/3.0) * PI * radius * radius * height; } void displayOutput(){ cout << "Volume of cone with radius of " << getRadius() << "…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY