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
How i can download play store?​
Phantasy [73]

Answer:

in Google type play Store and you will get the app and then click on that word install and it will get installed

Explanation:

hope this helps

3 0
4 years ago
A storyboard is an example of an implementation tool.
alexdok [17]

Answer:

That's not true. A storyboard is an organizer to plan out certain things and to know how something should look before doing the finished product.

Explanation:

7 0
3 years ago
Where are the instructions stored that the computer needs when it is switched on?
WARRIOR [948]
This is stored in the ROM (Read Only Memory)
I believe that is the answer, all i can come up with.
4 0
3 years ago
Lord Strawberry, a nobleman, collected birds. He had the finest aviary in Europe, so large that eagles did not find it uncomfort
creativ13 [48]

Answer:

That was a very great story that I totally did NOT read cause it too long 0-0.

Explanation:

To my ferns.....GET ON RN CAUSE I WONLEY T^T

Anyways wuv c'alls and have a good day :3

8 0
3 years ago
The average pH of citrus fruits is 2.2, and this value has been stored in the variable avg_citrus_pH . Provide a statement to di
olasank [31]

Answer:

The statement in Python is:

print("The average pH of citrus fruits is ",avg_citrus_pH)

Java

System.out.print("The average pH of citrus fruits is "+avg_citrus_pH);

C++

cout<<"The average pH of citrus fruits is "<<avg_citrus_pH;

Explanation:

The programming language is not stated; so, I answered the question in 3 languages (Python, Java and C++)

Assume that avg_citrus_pH has been declared and initialized; all you need to do is invoke a print statement and then append the variable

In Python, use print()

In c++, use cout<<

In Java, use System.out.print()

So, the statements are:

Python:

print("The average pH of citrus fruits is ",avg_citrus_pH)

Java

System.out.print("The average pH of citrus fruits is "+avg_citrus_pH);

C++

cout<<"The average pH of citrus fruits is "<<avg_citrus_pH;

8 0
3 years ago
Other questions:
  • Provide Java code to illustrate how to create an array, reference an array, and address an element of an array.
    13·1 answer
  • Why is color theory important
    6·2 answers
  • Which types of operating systems execute program independent of the users and generate output within a specific amount of time?
    5·1 answer
  • Differences between electromechanical era and electronic era in point.<br>PLZ HELP​
    6·1 answer
  • Web crawlers or spiders collect information from Web pages in an automated or semi-automated way. Only the text of Web pages is
    10·1 answer
  • Determine the number of cache sets (S), tag bits (t), set index bits (s), and block offset bits (b) for a 1024-byte 4-way set as
    5·1 answer
  • Choose the answer that best completes the
    8·2 answers
  • Drag the right word to it’s definition
    13·1 answer
  • What is a trusted computing base (TCB)? Hosts on your network that support secure transmissions The operating system kernel and
    9·1 answer
  • when inputting a formula into excel or other spreadsheet software, what components are required for the formula to function prop
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!