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.4, Problem 17.15CP
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.
Generic method:
- Methods that introduce their own type parameters are called as generic method.
- List of type parameters included inside the angle bracket which appears before the method’s return type.
- In generic method, type parameters are allowed to express the dependencies among the types of one or more arguments and its return type.
- The programmers are enabled to specify a single method declaration with a set of related methods.
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.
public 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
36
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
- Assignment 2: - Create the first Apex class or program -- In this apex class, we have to create 2 methods -- In the first method, we will take the argument of (account id), and the return type will be (the list of contact). -- In the second method, we will take the argument of (list of account) and the return type will be ( map)arrow_forwardIn C++, if a member of a class is private, we cannot access it outside the class, but what if the member variable is protected?arrow_forwardC++ 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…arrow_forward
- Overriding a method is defined as the ability to override the default method.arrow_forwardUsing C# Language: Programming PLO 3 Measured: Create control structures, methods with the appropriate parameters, and data structures of the appropriate type, and implement algorithms to solve problems. Design a class named Contractor. The class should keep the following information: Contractor name Contractor number Contractor start date Write one or more constructors and the appropriate accessor and mutator functions for the class. Write another class named Subcontractor that is derived from the Contractor class. The Subcontractor class should have member variables to hold the following information: Shift (an integer) Hourly pay rate (a double) The work is divided between two shifts, a day shift, and a night shift. The shift variable will hold an integer value representing the shift that the subcontractor will work. The day shift is 1 and the night shift is 2. Write one or more constructors and the appropriate accessor functions for the class. Demonstrate the classes…arrow_forwardIn 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_forward
- In terms of type declaration, how are rvalue references and lvalue references different?arrow_forwardWritten in Python It should have an init method that takes two values and uses them to initialize the data members. It should have a get_age method. Docstrings for modules, functions, classes, and methodsarrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,