1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Cloud [144]
3 years ago
5

Based on the data definition classes identified below, assume you wish to create a Dictionary class that inherits from the Book

class. In addition to title and cost, the Dictionary class must also store the number of words present in the dictionary. Write the code that will create a constructor in the dictionary class that passes in and sets the dictionary's title, cost, and number of words.
public class Book {
private String title;
private double cost;

public Book(String title) {
this(title, 0.00);
}

public Book(String title, double cost) {
this.title = title;
this.cost = cost;
}

public String getTitle() { return this.title; }
public double getCost() { return this.cost; }
}

public class Dictionary extends Book {
private double numWords;

// Create Contructor

}
Computers and Technology
1 answer:
Alex Ar [27]3 years ago
7 0
<h2>Answer:</h2>

//==============================

// Book class

//==============================

public class Book {

private String title;

private double cost;

public Book(String title) {

 this(title, 0.00);

}

public Book(String title, double cost) {

 this.title = title;

 this.cost = cost;

}

public String getTitle() {  

 return this.title;  

}

public double getCost() {  

 return this.cost;  

}

}

//==============================

// Dictionary class

//==============================

public class Dictionary extends Book {

private double numWords;

// Create Contructor

public Dictionary(String title, double cost, double numWords){

 super(title, cost);

 this.numWords = numWords;

}

}

<h2>Explanation:</h2>

The actual response to this question is shown in bold face in the above.

Line 1:

public Dictionary(String title, double cost, double numWords){

Here the header for the constructor for the Dictionary class is written which takes in three parameters - <em>title, cost </em>and <em>numWords</em>. These parameters will be used to set the values of the instance variables of the Dictionary class.

Remember that the Dictionary class extends from the Book class. Therefore, in addition to its <em>numWords</em> attribute, the Dictionary class also has the <em>title</em> and <em>cost</em> attributes.

Line 2:

super(title, cost)

Here, since the Dictionary class inherits from the Book class, it can also call the constructor of Book class to initialize two of its three variables which are <em>title</em> and <em>cost. </em>Hence the need for the super() method keyword. In other words, the super() in the Dictionary class is the constructor from the parent class and it is used here to set the dictionary's <em>title </em>and <em>cost </em>attributes.

Line 3:

this.numWords = numWords;

Here, the only attribute left to be set is the <em>numWords</em>. Therefore, the 3rd line sets this attribute to the parameter passed into the constructor in line 1.

Line 4:

}

Here, the block containing the Dictionary class constructor is being closed.

You might be interested in
Which of the following trims would be used at the beginning of a scene?
Ad libitum [116K]

Answer: a i think

Explanation:

6 0
3 years ago
if you upgrade your memory but notice the RAM count does not reflect the additional memory, what should you do ?
alisha [4.7K]

Try looking at your motherboard manual to see which dimm slots should be used first since putting memory in any slot could break the dual channel. Not giving your motherboard access to that ram. Or you probably used wrong memory since your memory has to be the exact same size and speed and type. Because 8gb ddr3 will not work with 8gb ddr4. 8gb ddr4 2400 MHz will also not work with 8gb ddr4 3200 MHz. And 8gb 3200 Mhz would not work with 16Gb 3200 mhz. Your ram should have the exact same specs.

3 0
4 years ago
In what way are a coffee maker and a dishwasher the same?<br><br>BY THE WAY THIS IS TEENBIZ
weeeeeb [17]
They both need electricity. Both used in the kitchen.
3 0
3 years ago
Read 2 more answers
Jeff wants to print quickly so he presses the Ctrl and the P. Jeff used a _____. macro invoice template shortcut
Allushta [10]
He used a keyboard shortcut.
3 0
4 years ago
What Windows utility can enable you to shut down an unresponsive application?
boyakko [2]

Answer:

Task manager

Explanation:

Allows you to force quit applications.

4 0
3 years ago
Read 2 more answers
Other questions:
  • Under which tab can you find the options for reusing slides from other presentations
    5·1 answer
  • TCP waits until it has received three duplicate ACKs before performing a fast retransmit. Why do you think the TCP designers cho
    13·1 answer
  • Evan accidentally entered an incorrect word when he was typing a document. Which keyboard shortcut should he use to undo the err
    5·2 answers
  • Which of the following is FALSE? Select one: a. The fast-paced and collaboration-based business environment makes email less use
    10·1 answer
  • What is a credit limit? athe required payment to your credit card company. bthe amount of interest you are charged each month. c
    10·1 answer
  • Explain the importance of technology in at least 100 words
    11·1 answer
  • Я люблю есть гнезда петух
    11·1 answer
  • What is the primary difference among a domain model, an analysis model, and a design model for the same project?
    15·1 answer
  • Transitive spread refers to the effect of the original things transmitted to the associate things through the material, energy o
    6·1 answer
  • Computers are often used to create financial model. One of the features which make a spreadsheet suitable for this is the abilit
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!