EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
Expert Solution & Answer
Book Icon
Chapter 11, Problem 3PE

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...

Blurred answer
Students have asked these similar questions
Task 3. i) Compare your results from Tasks 1 and 2. j) Repeat Tasks 1 and 2 for 500 and 5,000 elements. k) Summarize run-time results in the following table: Time/size n String StringBuilder 50 500 5,000
Can you please solve this without AI
1. Create a Vehicle.java file. Implement the public Vehicle and Car classes in Vehicle.java, including all the variables and methods in the UMLS. Vehicle - make: String model: String -year: int + Vehicle(String make, String, model, int, year) + getMake(): String + setMake(String make): void + getModel(): String + setModel(String model): void + getYear(): int + set Year(int year): void +toString(): String Car - numDoors: int + numberOfCar: int + Car(String make, String, model, int, year, int numDoors) + getNumDoors(): int + setNumDoors (int num Doors): void + toString(): String 2. Create a CarTest.java file. Implement a public CarTest class with a main method. In the main method, create one Car object and print the object using System.out.println(). Then, print the numberOfCar. Your printing result must follow the example output: make Toyota, model=Camry, year=2022 numDoors=4 1 Hint: You need to modify the toString methods in the Car class and Vehicle class!
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr