Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 17, Problem 4AW
Program Plan Intro
Generic Class:
- It is a class in which the class name is followed by the type parameter section.
- In generic class, one or more type arguments are separated by commas.
- The programmers are enabled to specify a single class declaration with a set of related type.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Describe how you can use an interface as an alternative to a class to specify the type for a parameter.
C++ Language Please
Write a program that implements four classes: NPC, Flying, Walking, and Generic for a fantasy roleplaying game. Each class should have the following attributes and methods:
NPC -a parent class that defines methods and an attribute common to all non-player characters (npc) in the game.
a private string variable named name, for storing the name of the npc.
a default constructor for setting name to "placeholder".
an overloaded constructor that sets name to a string argument passed to it.
setName - a mutator for updating the name attribute
getName - an accessor for returning the npc name
printStats - a pure virtual function that will be overridden by each NPC subclass.
Flying - a subclass of NPC that defines a flying npc in the game
a private int variable named flightSpeed for tracking the speed of the npc.
a default constructor for setting flightSpeed to 0 and name to "Flying" using setName.
setFlightSpeed - a mutator that accepts an integer as it's only argument…
Design a generic class to hold the following information about a bank account. - Balance, number of deposits this month, number of withdrawals, annual interest rate, monthly service charges.
The class should have the following member functions constructor: accepts arguments for the balance and annual interest rate deposit: A virtual function that accepts an argument for the amount of the deposit. The function should add the argument to the account balance. It should also increment the variable holding the number of deposits. withdraw: A virtual function that accepts an argument for the amount of the deposit.
The function should subtract the argument to the account balance. It should also increment the variable holding the number of deposits. calcInt: A virtual function that updates the balance by calculating the monthly interest earned by the account, and adding this interest to the balance. This is performed by the following formulas: Monthly Interest Rate = (Annual Interest Rate /12)…
Chapter 17 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Ch. 17.1 - Prob. 17.1CPCh. 17.1 - When ArrayList is used as a non-generic class, why...Ch. 17.1 - Suppose we use the following statement to...Ch. 17.1 - Assume we have used the statement shown in...Ch. 17.2 - Prob. 17.5CPCh. 17.2 - Prob. 17.6CPCh. 17.2 - Prob. 17.7CPCh. 17.2 - Prob. 17.8CPCh. 17.3 - Prob. 17.9CPCh. 17.3 - Prob. 17.10CP
Ch. 17.3 - Prob. 17.11CPCh. 17.3 - Prob. 17.12CPCh. 17.3 - Prob. 17.13CPCh. 17.3 - Prob. 17.14CPCh. 17.4 - Prob. 17.15CPCh. 17.5 - Prob. 17.16CPCh. 17.5 - Prob. 17.17CPCh. 17.6 - Prob. 17.18CPCh. 17.6 - Prob. 17.19CPCh. 17.6 - Prob. 17.20CPCh. 17.8 - Prob. 17.21CPCh. 17.8 - Prob. 17.22CPCh. 17.9 - Prob. 17.23CPCh. 17.9 - During the process of erasure, when the compiler...Ch. 17.9 - Prob. 17.25CPCh. 17 - Prob. 1MCCh. 17 - Prob. 2MCCh. 17 - Look at the following method header: void...Ch. 17 - Look at the following method header: void...Ch. 17 - Look at the following method header: void...Ch. 17 - Look at the following method header: void...Ch. 17 - Prob. 7MCCh. 17 - Prob. 8MCCh. 17 - Prob. 9MCCh. 17 - The process used by the Java compiler to remove...Ch. 17 - True or False: It is better to discover an error...Ch. 17 - Prob. 12TFCh. 17 - True or False: Type parameters must be single...Ch. 17 - Prob. 14TFCh. 17 - Prob. 15TFCh. 17 - True or False: You cannot create an array of...Ch. 17 - Prob. 17TFCh. 17 - Prob. 18TFCh. 17 - Prob. 1FTECh. 17 - Assume the following is a method header in a...Ch. 17 - public class MyClassT { public static void...Ch. 17 - public class PointT extends Number super Integer {...Ch. 17 - Assume there is a class named Customer. Write a...Ch. 17 - Assume names references an object of the...Ch. 17 - Prob. 3AWCh. 17 - Prob. 4AWCh. 17 - Prob. 5AWCh. 17 - Prob. 6AWCh. 17 - Prob. 7AWCh. 17 - Prob. 1SACh. 17 - Look at the following method header: public T...Ch. 17 - Prob. 3SACh. 17 - Do generic types exist at the bytecode level?Ch. 17 - Prob. 5SACh. 17 - When the compiler encounters a class, interface,...Ch. 17 - Prob. 1PCCh. 17 - Prob. 2PCCh. 17 - Prob. 3PCCh. 17 - Prob. 4PCCh. 17 - Prob. 5PCCh. 17 - Prob. 6PCCh. 17 - Prob. 7PC
Knowledge Booster
Similar questions
- In C++, create a class student with member int ID and string name, and a default constructor that prints "Object created". Inside main create an object of student class.arrow_forwardIN C++ Lab #6: Shapes Create a class named Point. private attributes x and y of integer type. Create a class named Shape. private attributes: Point points[6] int howManyPoints; Create a Main Menu: Add a Triangle shape Add a Rectangle shape Add a Pentagon shape Add a Hexagon shape Exit All class functions should be well defined in the scope of this lab. Use operator overloading for the array in Shape class. Once you ask the points of any shape it will display in the terminal the points added.arrow_forwardIn C++, Create a class called Date that includes three data members: amonth(type int), a day(type int), and a year(type int). The Date class willhave a constructor with three parameters to initialize the three data members.You may assume the values provided for the year and day are correct, but makesure that the month value is in the range 1-12; if it isn't, set the month to1. Provide set and get functions for each data member. Provide a memberfunction displayDate that displays the date in format MM/DD/YYYY.Write a test program that prompts the user to input the month, the day,and the year and uses your Date class to output the formatted date.arrow_forward
- In C++ Programming this assignment, you are required to create a class called Circle. The class must have a data field called radius that represents the radius of the circle. The class must have the following functions: (1) Two constructors: one without parameters and another one with one parameter. Each of the two constructors must initialize the radius (choose your own values). (2) Set and get functions for the radius data field. The purpose of these functions is to allow indirect access to the radius data field (3) A function that calculates the area of the circle (4) A function that prints the area of the circle Test your code as follows: (1) Create two Circle objects: one is initialized by the first constructor, and the other is initialized by the second constructor. (2) Calculate the areas of the two circles and displays them on the screen (3) Use the set functions to change the radius values for the two circles. Then, use get functions to display the new values in your main…arrow_forwardpublic class Point { Create two variables: 1. Generic Variable: Variable Name: data 2. Generic Point: Varibale Name: next 10 11 12 13 /* 14 Constructor that takes in two parameters (see above comment) */ 15 16 17 18 19 20 /* 21 Setters and getters 22 */ 23 24 wwwm 25 26 /* 27 tostring: output should be in the format: 28 (data)--> (next) 29 Example: 30 Point p1,p2; 31 p1.data = 4; 32 p1.next = p2; 33 p1.toString () would be: (4) -->(p2) 34 35 36arrow_forwardC++ In this problem, you will use the Bubble class to make images of colorful bubbles. You will use your knowledge of classes and objects to make an instance of the Bubble class (aka instantiate a Bubble), set its member variables, and use its member functions to draw a Bubble into an image. Every Bubble object has the following member variables: X coordinate Y coordinate Size (i.e. its radius) Color Complete main.cc Your task is to complete main.cc to build and draw Bubble objects based on user input. main.cc already does the work to draw the Bubble as an image saved in bubble.bmp. You should follow these steps: First, you will need to create a Bubble object from the Bubble class. Next, you must prompt the user to provide the following: an int for the X coordinate, an int for the Y coordinate, an int for the Bubble's size, and a std::string for the Bubble's color. Next, you must use the user's input to set the new Bubble object's x and y coordinates, the size, and the color using…arrow_forward
- You are tasked with defining a class Course that includes the following data members: CourseNum (int). -CourseName(string) -CreditHours(int), Department(string). Assuming you have the template: class Coursearrow_forwardWrite a program to create a class teacher with the following data members.ID: Can be accessed only from the teacher class and derived classes of the teacher.Age: Can be accessed from all the classes and packages in the application.Phone Number: Can be accessed only from the classes inside the same package.Write the constructor function. Derive a class Math_teacher from the teacher class, add the following two data members in the Math_teacher class.Room Number: This can be accessed by all the classes in the application.Course_ID: This can be accessed by all the classes in the same package.Write the constructor function.arrow_forwardQ#: Write a class Email that contain the following fields, which other classes may not access: To From Subject Content Write a function member called SendEmail that initialize all the class fields through information passing as parameters. SendEmail method will print the content of email only. Write a driver class with any name that must have a main method. Inside main, call SendEmail.arrow_forward
- In C++ class SaleItem{public:double getprice();void setprice(double);void setName(string);string getName();double TotalItemsPrice(int);private:double price;string name;}; In the class declaration above, what is the name of the class? Which lines have member access specifiers? Which lines contain data members of the class? Which lines contain accessor functions? Which lines contain mutator functions?arrow_forwardInside the FlightController class, you will define an object of type FlightSchedule which willcontain an array of 3 objects of type Flight. In your Flight objects, the constructor of theseobjects will ask from the user for the inputs of: flight name, launch hour, launch minutes,flight duration. The value of state of the Flight object will be assigned to “Idle” as a defaultvalue in the constructor also and you will call the member function within the Flight classwhich will calculate the landing time for your flight object by using the duration and thelaunch time. Definition of Flight class will also contain the necessary getters and setters thatare given in the diagram and needed throughout your program.In the constructor of your FlightController you will need to define a pointer that will point tothe adress of the FlightSchedule object you have created. You will send that pointer into thefunctions launchSchedule and landingSchedule in your base classes and these functions willperform a…arrow_forwardInside the FlightController class, you will define an object of type FlightSchedule which willcontain an array of 3 objects of type Flight. In your Flight objects, the constructor of theseobjects will ask from the user for the inputs of: flight name, launch hour, launch minutes,flight duration. The value of state of the Flight object will be assigned to “Idle” as a defaultvalue in the constructor also and you will call the member function within the Flight classwhich will calculate the landing time for your flight object by using the duration and thelaunch time. Definition of Flight class will also contain the necessary getters and setters thatare given in the diagram and needed throughout your program.In the constructor of your FlightController you will need to define a pointer that will point tothe adress of the FlightSchedule object you have created. You will send that pointer into thefunctions launchSchedule and landingSchedule in your base classes and these functions willperform a…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,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author: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,
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT