
Explanation of Solution
Program:
File name: “NewspaperSubscription.java”
//Define an abstract class named NewspaperSubscription
public abstract class NewspaperSubscription
{
//Declare required instance variables
protected String name;
protected String address;
protected double rate;
//Define required getter function for the
//instance variable name
public String getName()
{
//Return the value
return name;
}
//Define required setter function for the instance
//variable name
public void setName(String n)
{
//Set the value of the instance variable name by
//assigning the value in the function parameter to
//the variable name
name = n;
}
//Define required getter function for the instance
//variable address
public String getAddress()
{
//Return the value
return address;
}
//Define the required getter function getRate() for
//the instance variable rate
public double getRate()
{
//Return the value
return rate;
}
//Declare the prototype of an abstract function setAddress()
public abstract void setAddress(String s);
}
File name: “PhysicalNewspaperSubscription.java”
//Define a class named PhysicalNewspaperSubscription
//inheriting the class NewspaperSubscription
public class PhysicalNewspaperSubscription extends NewspaperSubscription
{
//Define the overriden method setAddress()
public void setAddress(String a)
{
//Declare and initialize required Boolean variables
//to store the result of the condition if the given
//address includes a digit or not
boolean hasDigit = false;
address = a;
//Traverse the character array using a for each loop
for(int x = 0; x < a.length(); ++x)
//If the current character is a digit, then
//assign true to the variable hasDigit
if(Character.isDigit(a.charAt(x)))
hasDigit = true;
//If the value of the variable hasDigit is true,
//then assign 15 to the instance variable rate
if(hasDigit)
rate = 15.00;
//Otherwise, display an appropriate message and
//assign 0 to the instance variable rate
else
{
rate = 0;
//Print the result
System.out.print("\nAddress must contain a digit ");
}
}
}
File name: “OnlineNewspaperSubscription.java”
//Define a class named OnlineNewspaperSubscription
//extending the class NewspaperSubscription
public class OnlineNewspaperSubscription extends NewspaperSubscription
{
//Define the overriden method setAddress()
public void setAddress(String a)
{
//Declare and initialize required Boolean variables
//to store the result of the condition if the given
//address includes a sign or not
boolean hasAtSign = false;
address = a;
//Traverse the character array using a for each loop
for(int x = 0; x < a...

Want to see the full answer?
Check out a sample textbook solution
Chapter 11 Solutions
EBK JAVA PROGRAMMING
- CHATGPT GAVE ME WRONG ANSWER PLEASE HELParrow_forwardHELP CHAT GPT GAVE ME WRONG ANSWER Consider the following implementation of a container that will be used in a concurrent environment. The container is supposed to be used like an indexed array, but provide thread-safe access to elements. struct concurrent_container { // Assume it’s called for any new instance soon before it’s ever used void concurrent_container() { init_mutex(&lock); } ~concurrent_container() { destroy_mutex(&lock); } // Returns element by its index. int get(int index) { lock.acquire(); if (index < 0 || index >= size) { return -1; } int result = data[index]; lock.release(); return result; } // Sets element by its index. void set(int index, int value) { lock.acquire(); if (index < 0 || index >= size) { resize(size); } data[index] = value; lock.release(); } // Extend maximum capacity of the…arrow_forwardWrite a C program using embedded assembler in which you use your own function to multiply by two without using the product. Tip: Just remember that multiplying by two in binary means shifting the number one place to the left. You can use the sample program from the previous exercise as a basis, which increments a variable. Just replace the INC instruction with SHL.arrow_forward
- R languagearrow_forwardQuestion 1 (15 Points) Inheritance: In this question, we are going to create a new subclass of the SimpleGeometricObject class, named Triangle. Create a SimpleGeometricObject.java and Copy the source code of the SimpleGeometricObject class from the following link: https://liveexample.pearsoncmg.com/html/SimpleGeometricObject.html TASK 1: Create a Triangle class that extends the SimpleGeometricObject class in Eclipse, following the below UML diagram. + base:double = 5 + height:double = 10 Triangle + Triangle() + Triangle(newBase: double, newHeight: double) + getArea(): double + setBase(): void + setHeight(): void + getBase(): double + getHeight(): doublearrow_forwardQuestion 2 (10 Points): String vs. StringBuilder Create a Question2.java file and finish the following tasks: Task 1. a) Create a 1D array of integers to store 50 integers. b) Store values from 0 to 49 in the array you just created. c) Create a new String Object using no-arg constructor. d) Using for loop to add the array elements one by one to the String (one per loop iteration) Hint: to append an element to a String, use the + operator. e) Output the String on the console. Record and display a run-time it took to append all integers to the String (record run-time of 1.d.)). Please submit a screenshot. The screenshot should match the following example: 012345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 it took 196708 nanoseconds to append 50 integers to the String.| Hint: You can use the following statements to record run-time. long begin, end, time; // we will measure time it took begin = System.nanoTime(); //we measure in nanoseconds. // put…arrow_forward
- Answer this Java OOP question below: Discuss the challenges and benefits of using multiple levels of inheritance in a class hierarchy. How can deep inheritance structures impact the maintainability and readability of code?arrow_forwardAnswer the Java OOP question below: Explain the relationship between a superclass and a subclass. How do the principles of encapsulation and abstraction play a role in this relationship? In your experience, how do you decide what should be included in a superclass versus a subclass? Share an example where a well-defined superclass-subclass hierarchy improved your code.arrow_forward1.) Consider the problem of determining whether a DFA and a regular expression are equivalent. Express this problem as a language and show that it is decidable. ii) Let ALLDFA = {(A)| A is a DFA and L(A) = "}. Show that ALLDFA is decidable. iii) Let AECFG = {(G)| G is a CFG that generates &}. Show that AECFG is decidable. iv) Let ETM {(M)| M is a TM and L(M) = 0}. Show that ETM, the complement of Erm, is Turing-recognizable. Let X be the set {1, 2, 3, 4, 5} and Y be the set {6, 7, 8, 9, 10). We describe the functions f: XY and g: XY in the following tables. Answer each part and give a reason for each negative answer. n f(n) n g(n) 1 6 1 10 2 7 2 9 3 6 3 8 4 7 4 7 5 6 5 6 Aa. Is f one-to-one? b. Is fonto? c. Is fa correspondence? Ad. Is g one-to-one? e. Is g onto? f. Is g a correspondence? vi) Let B be the set of all infinite sequences over {0,1}. Show that B is uncountable using a proof by diagonalization.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr




