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 solutionChapter 11 Solutions
EBK JAVA PROGRAMMING
- Create an abstract class called Shape with the protected member String shapeName. It should have two public abstract methods getArea and getVolume. Finally, it should contain a public String method called getName which returns the shapeName. You should create a Circle class, Square class, Rectangle class, Triangle class which extend the Shape class. Each class should contain the necessary private variables. For example, a square has a side. The area and the volume can all be derived from the side value so the only private variable necessary for the square class is the side. The circle requires a radius. The triangle requires a base, length and a height. Finally, the rectangle requires length, height and width. The classes should also contain constructors and appropriate implementations of the two abstract methods getArea and the getVolume. **Shape Calculator** Enter 1 for a Circle Enter 2 for a Square Enter 3 for a Rectangle Enter 4 for a Triangle Enter 5 to Exit You should use a…arrow_forward1. Create a Student class that implements the Person interface. As well as storing the students name and email, also store their course grade (e.g A, B, C) in a member variable. The grade should be accessible via a getGrade method. For the implementation of getDescription return a message along the lines of “A C grade student”, substituting the students actual grade.2. Create a Lecturer class that implements the Person interface. This class should also store the subject that the lecturer teaches. Add a getSubject method, and implement getDescription so that it returns a suitable message, e.g. “Teaches Biology”.3. Create a third class, Employee that implements the interface. This should also store the name of the department the Employee works in (available via getDepartment). Again, getDescription should return a suitable message.arrow_forwardWe are working in 2D and programming in C#. Create a Point class to represent points in 2D. Create an abstract base class named Shape. It should have a position property as a Point. It should be designed as having Move and Resize methods. Create a Line class using Points, derived from Shape class. Its position should be the center of the line. Create a Polygon class representing a closed polygon of Lines, derived from Shape class. Note that, at construction time, Lines may not be provided in order. The continuity and number of the lines should also be checked for a properly closed Polygon. All geometric entities should be moveable. All shapes should be resizable without changing their central positions. All shapes' positions should be their centroids. Shapes should have areas calculated. Write an example C# Console code to demonstrate your program's abilities.arrow_forward
- Create an interface RateConstants that includes a constant value for the subscription rate that is $15.5. Create a class NewspaperSubsciption that implements the RateConstants interface. A NewspaperSubscription class includes fields for the subscriber’s name and rate. The constructor requires data for name only. The rate should be set to the subscription rate of RateConstants. The name should not contain digits. If the name contains digits, raise an exception InvalidNameException. Create a class name InvalidNameException. The NewspaperSubscription class should throw an exception named InvalidNameException when it receives an invalid subscriber’s name. Create a class PhysicalNewspaperSubcription that extends NewspaperSubscription class. The PhysicalNewspaperSubscription class should have a field for subscription type and a constructor to sets the subscription type to “PhysicalSUB”. The PhysicalNewspaperSubscription class should also have a toString() method to displays all the…arrow_forwardCreate a subclass of the Employee class from Question 2 named ShiftSupervisor. Add the salary and bonus attributes to it, and override_init_and_str_accordingly. Add the appropriate accessor and mutator methods and check the functionality by prompting a user to input the data for a Shift Supervisor object. Use_str__ to print the result.arrow_forwardThis is the question - Create an abstract Student class for Parker University. The class contains fields for student ID number, last name, and annual tuition. Include a constructor that requires parameters for the ID number and name. Include get and set methods for each field; the setTuition() method is abstract. Create three Student subclasses named UndergraduateStudent, GraduateStudent, and StudentAtLarge, each with a unique setTuition() method. Tuition for an UndergraduateStudent is $4,000 per semester, tuition for a GraduateStudent is $6,000 per semester, and tuition for a StudentAtLarge is $2,000 per semester. Code I was given - public class GraduateStudent extends Student { public static final double GRAD_TUITION = 6000; public GraduateStudent(String id, String name) { // write your code here } public void setTuition() { tuition = GRAD_TUITION; } } public abstract class Student { private String id; private String lastName;…arrow_forward
- Create a class Course to describe a course according to the following requirements: A course has three attributes: courseName, courseCode, fees. Create a constructor without parameters to initialize all the instance variables to default values (0 for numbers and "" for a string). Create a constructor to initialize all the attributes to specific values. Add all setter and getter methods Create a tester class with the main method. The tester class must be named using your first and last In this class performs the following: Create a course object c1 using the default constructor. Create a course object c2 with the following information: courseName =” object oriented programing”, courseCode = “CS230” , fees = a value from your choice. Change the course fees of c2 to your age. Print the course information of c2 using getter methods I attached Typical run of the programarrow_forwardDefine the Circle2D class that contains: Two double data fields named x and y that specify the center of the circle with get methods. A data field radius with a get method. A no-arg constructor that creates a default circle with (0, 0) for (x, y) and 1 for radius. A constructor that creates a circle with the specified x, y, and radius. A method getArea() that returns the area of the circle. A method getPerimeter() that returns the perimeter of the circle. A method contains(double x, double y) that returns true if the specified point (x, y) is inside this circle. See Figure 10.14(a). A method contains(Circle2D circle) that returns true if the specified circle is inside this circle. See Figure 10.14(b). A method overlaps(Circle2D circle) that returns true if the specified circle overlaps with this circle. See the figure below. Figure (a) A point is inside the circle. (b) A circle is inside another circle. (c) A circle overlaps another circle. Draw the UML diagram for the class.…arrow_forwardThe Profile class constructor has a self parameter and three additional parameters: status, age, and username. Input values status1, age1, and username1 are read representing the information of a profile. Instantiate a new instance of Profile by assigning profile1 with an instance of Profile with status1 as status, age1 as age, and username1 as username.arrow_forward
- Is there a different way of doing this problem? Question: Create a class AccessPoint with the following attributes: x - a double representing the x coordinate y - a double representing the y coordinate range - an integer representing the coverage radius status - On or Off Add constructors. The default constructor should create an access point object at position (0.0, 0.0), coverage radius 0, and Off. Add accessor and mutator functions: getX, getY, getRange, getStatus, setX, setY, setRange and setStatus. Also, add a set function that sets the location coordinates and the range. Add the following member functions: move and coverageArea. Add a function overlap that checks if two access points overlap their coverage and returns true if they overlap. Add a function signalStrength that returns the wireless signal strength as a percentage. The signal strength decreases as one moves away from the access point location. Test your class by writing a main function that creates five access…arrow_forwardCreate a class BeautyProduct with name, color, brand. Provide Constructors, getters, setters and also write toString method. Now create a class Lipstick which extends the class BeautyProduct as Lipstick is-a Beauty Product it has totalVolume, remainingVolume, price, texture (gloss, matt) as private data members. Provide Constructors, getters, setters and an apply() method whenever this method is called a beauty item is applied and its volume decreases by 10.This should also check that volume must not be zero if it then u have to throw exception. Also write toString method which prints all details like name, color, brand, price, texture and volume. Create another class foundation having totalVolume, remainingVolume, price, texture (liquid, cake) and lastingTime (number of hours foundation remain intact on face and does not crease) as private data members. This also extends the base class i.e. BeautyProduct. Provide Constructors, getters, setters and an apply() method whenever this…arrow_forwardPerson and Customer Classes Write a class named (Person) with data attributes for a person’s name, address, and telephone number. Provide accessors/getters and mutators/setters for each attribute. Write a displayPerson() to print out the attributes of the Person. Next, write a class named (Customer) that is a subclass of the (Person) class. The (Customer) class should have a data attribute for a customer number, and a Boolean data attribute indicating whether the customer wishes to be on a mailing list. Provide accessors/getters and mutators/setters for each attribute. Write a display customer() to print out the attributes of the Customer. Demonstrate an instance of the (Customer) class in a simple program.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,