Concept explainers
Explanation of Solution
Program:
File name: “Division.java”
//Define an abstract class named Division
public abstract class Division
{
//Declare required instance variables
protected String divisionTitle;
protected int acctNum;
//Define the Division function
public Division(String title, int acct)
{
//Set the company’s division name and the account number
divisionTitle = title;
acctNum = acct;
}
//Define the function display()
public abstract void display();
}
File name: “InternationalDivision.java”
//Define a class named InternationalDivision
//inheriting the class Division
public class InternationalDivision extends Division
{
//Declare required instance variables
protected String country;
protected String language;
//Define the overriden method InternationalDivision()
public InternationalDivision(String title, int acct, String cty, String lang)
{
//Call the superclass method
super(title, acct);
//Set the country in which the division is located
//and the language spoken
country = cty;
language = lang;
}
//Define the function display()
public void display()
{
//Print the result
System.out.println("International Division: " + divisionTitle +
" Acct #" + acctNum + "\nLocated in " + country +
" Language is " + language);
}
}
File name: “DomesticDivision.java”
//Define a class named DomesticDivision
//inheriting the class Division
public class DomesticDivision extends Division
{
//Declare required instance variable
protected String state;
//Define the overriden method DomesticDivision
public DomesticDivision(String title, int acct, String st)
{
//Call the superclass method
super(title, acct);
//Set the state in which the division is located
state = st;
}
//Define the function display()
public void display()
{
//Print the result
System...
Trending nowThis is a popular solution!
Chapter 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_forwardDesign a Friend class that the following members: • A field for the name of the friend (a string). •A field for the cell phone number of the friend (a string). • A field for the gender of the friend (a character F or M). • A static field numObjects (integer). Constructors: A default constructor and a parameterized constructor. Accessors methods for the data fields. Set methods for the cell phone data field and the numObjects field. A toString() method that displays the data fields. Design a testFriend driver class that has an arrFriends array that can hold up to a maximum of 15 objects. Write a static fillArray() method that receives the arrFriends array and allow the user to enter the information of a number of friends. Save the objects to the array. Return the array to the call statement. Write a static displayArray) method that receives the arrFriends array as parameter and display a numbered list of information on the objects saved in the array. Write a static sortData() method…arrow_forwardCreate a class called Employee that contains two attributes: name and number. Next, write a class named Production Worker that is a subclass of the Employee class. The Production Worker class should add extra attributes called shift_number (an integer, either 1 or 2) and pay_rate. Write the appropriate accessor and mutator methods for each class. Once you have written the classes, write a program that creates an object of the Employee class and an object of the Production Worker class and prompts the user to enter data for each of the object's data attributes. Store the data in the object, then use the object's accessor methods to retrieve it and display it on the screen.arrow_forward
- The program is Java. Part 1. Create an abstract Parent Class called “Vehicle” strictly based on the UML. (Do not include anything extra, do not miss any data fields or methods. # denotes protected visibility modifier.). Add comments stating where data fields, constructors, toString() and other methods(if any). Part 2. Create a child Class called “ElectricVehicle” strictly based on the UML. Add comments stating where data fields, constructors, toString() and other methods(if any). Part 3. Write a main method inside Vehicle class, having the following: a) Create a new instance of the “ElectricVehicle” class using the no-arg constructor and assign it to the object reference of type “Vehicle” class. b) Create a new instance of the “ElectricVehicle” class using the overloaded constructor and assign it to the object reference of type “Vehicle” class. c) Display the content of both the objects(using toString() method)arrow_forwardCreate an abstract NewspaperSubscription class with fields for the subscriber name, address, and rate. Include get and set methods for the name field and get methods for the address and subscription rate; the setAddress() method is abstract. Create two subclasses named PhysicalNewspaperSubscription and OnlineNewspaperSubscription. The parameter for the setAddress() method of the PhysicalNewspaperSubscription class must contain at least one digit; otherwise, an error message is displayed and the subscription rate is set to 0. If the address is valid, the subscription rate is assigned $15. The parameter for the setAddress() method of the OnlineNewspaperSubscription class must contain an at sign (@) or an error message is displayed. If the address is valid, the subscription rate is assigned $9. Finally, write an application that declares several objects of both subscription subtypes and displays their data fieldsarrow_forwardQuestion 6 Create a set of classes and interface for the following scenario: Define an interface called Classical Music, which contains a get Year method that returns the year the classical album released. Create an abstract class Called CD. This class contains the title as String, and playingTime as integer (e.g. 60 minutes). Include a constructor to initialize all the data fields. Create an abstract method called printPlayingTime to show the CD playing details. Make sure all the data fields can be accessed directly from the child classes. Create a class called Album that inherits from the CD and Classical Music. Include a data field called year as integer type. Create a constructor to initialize all the data members. Override the getYear method to return the released year. Override the printPlayingTime method. If the CD title is more than 10 characters, this method will print the first 10 characters, followed by the three ellipse dots and the playing time. For example: Thriller 60…arrow_forward
- Create abstract class Pet , which is the abstract superclass of all animals. Declare a integer attribute called legs, which records the number of legs for this animal. Define a constructor that initializes the legs attribute. Declare an abstract method eat. Declare a concrete method walk that prints out something about how the animals walks (include the number of legs). Create the Dog class. The Dog class extends the Pet class. This class must include a String attribute to store the name and food of the pet Define a default constructor that calls the superclass constructor to specify that all dogs have 4 legs and name. override the eat and walk method. Create the Cat class that extends Pet. This class must include a String attribute to store the name of the pet, and a string to save food . Define a constructor that takes one String parameter that specifies the cat's name and food. This constructor must also call the superclass constructor to specify that all cats have four legs.…arrow_forwardCreate abstract class Pet , which is the abstract superclass of all animals. Declare a integer attribute called legs, which records the number of legs for this animal. Define a constructor that initializes the legs attribute. Declare an abstract method eat. Declare a concrete method walk that prints out something about how the animals walks (include the number of legs). Create the Dog class. The Dog class extends the Pet class. This class must include a String attribute to store the name and food of the pet Define a default constructor that calls the superclass constructor to specify that all dogs have 4 legs and name. override the eat and walk method. Create the Cat class that extends Pet. This class must include a String attribute to store the name of the pet, and a string to save food . Define a constructor that takes one String parameter that specifies the cat's name and food. This constructor must also call the superclass constructor to specify that all cats have four legs.…arrow_forward3. Design a user-defined class called Course. Each course object will hold data about a course. The data includes courseID, courseName, credits and instructorName. Define the instance variables required of the appropriate type. Provide only get methods along with toString() and equals() methods. Design another user-defined class called Student. Each student object will hold data on name, GPA and courseList. Make sure to define courseList as an ArrayList holding references to Course objects Implement a constructor that will take values to initialize name, and gpa while courseList is initialized to an ArrayList() object. Provide the following get methods: getStudent ID ( ), getName(), getGPA (), get Gender(), and get CourseList() Note: the getCouresList() method will return a copy of the coureList arraylist with copies of course objects. Provide the following set methods: setName(), setGPA (), setGender() Another method: addCourse () that will take a Course object and add it to the…arrow_forward
- Create abstract class Pet , which is the abstract superclass of all animals.Declare a integer attribute called legs, which records the number of legs for this animal.Define a constructor that initializes the legs attribute.Declare an abstract method eat.Declare a concrete method walk that prints out something about how the animals walks (include the number of legs).Create the Dog class.The Dog class extends the Pet class.This class must include a String attribute to store the name and food of the petDefine a default constructor that calls the superclass constructor to specify that all dogs have 4 legs and name.override the eat and walk method.Create the Cat class that extends Pet.This class must include a String attribute to store the name of the pet, and a string to save food .Define a constructor that takes one String parameter that specifies the cat's name and food. This constructor must also call the superclass constructor to specify that all cats have four legs.Override walk…arrow_forwardCreate a class named Poem that contains the following fields: title - the name of the poem (of type String) lines - the number of lines in the poem (of type int) Include a constructor that requires values for both fields. Also include get methods to retrieve field values. Create three subclasses: Couplet, Limerick, and Haiku. The constructor for each subclass requires only a title; the lines field is set using a constant value. A couplet has two lines, a limerick has five lines, and a haiku has three lines. ***Can I also get an explaination for each step thank you so much for all of your help ^_^**** import java.util.*; public class DemoPoems { public static void main(String[] args) { Poem poem1 = new Poem("The Raven", 84); Couplet poem2 = new Couplet("True Wit"); Limerick poem3 = new Limerick("There was an Old Man with a Beard"); Haiku poem4 = new Haiku("The Wren"); display(poem1); display(poem2); display(poem3);…arrow_forwardCreate a class named Poem that contains the following fields: title - the name of the poem (of type String) lines - the number of lines in the poem (of type int) Include a constructor that requires values for both fields. Also include get methods to retrieve field values. Create three subclasses: Couplet, Limerick, and Haiku. The constructor for each subclass requires only a title; the lines field is set using a constant value. A couplet has two lines, a limerick has five lines, and a haiku has three lines. These are the provided classes and subclasses : public class Poem { // Define the Poem class here } public class Limerick { // Define the Limerick class here } public class Haiku { // Define the Haiku class here } public class Couplet { // Define the Couplet class here } import java.util.*; public class DemoPoems { publicstaticvoidmain(String[] args) { Poem poem1 =newPoem("The Raven",84); Couplet poem2 =newCouplet("True Wit"); Limerick poem3 =newLimerick("There was an…arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT