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
- Write a class named Employee which implements Comparable Interface with name and salary as data field. Add a constructor with argument name and salary. Add getter and Setter for name and salary. Add CompareTo() method for the data Name. Write a class named Manager which inherits the Employee class. Add an instance variable, named department, of type String. Add a constructor in the subclass class with arguments name, salary, department and a toString() method that prints the manager’s name, department, and salary [Hint: Add a toString( ) method in the super class as well] Create 3 objects of Manager with following arguments 1. (Zayed, 500), 2. ( Ahmed, 700) 3. ( Faisal, 600) Create an Array object Add the above 3 objects into an Array object and Sort by Name and Display Create an object Employee class with argument (Zayed, 500, IT) Display the 1. Name 2. Salary 3. Department by using tostring() method.arrow_forwardWrite a class named Employee which implements Comparable Interface with name and salary as data fields Add a constructor with argument name and salary. Add getter and Setter for name and salary. Add CompareTo() method for the data Salary. Write a class named Manager which inherits the Employee class. Add an instance variable, named department, of type String. Add a constructor in the subclass class with arguments name, salary, department and a toString() method that prints the manager’s name, department, and salary [Hint: Add a toString( ) method in the super class as well] Create 3 objects of Manager with following arguments 1. (Zayed, 500), 2. ( Ahmed, 700) 3. ( Faisal, 600) Add the above 3 objects into an ArrayLIst object and Sort by Salary and Display. Create an object Employee class with (Zayed, 500,IT) and display the 1. Name 2. Salary 3. Department by using tostring() method.arrow_forwardCreate an abstract super class called Employee with the following attributes: name : String and the following methods getter and setter for the one attribute three constructors an abstract method called getSalary() equals() toString() Create a sub class of Employee called Faculty with the following attribute yearlyPay : double department: String and the following methods getter and setter for the attributes three constructors getSalary() that returns the yearlyPay divided by 52 equals() toString() Create a sub class of Employee called Staff with the following attributes: hoursWorked : double payrate : double and the following methods getters and setters for the two attributes three constructors getSalary() that returns the weekly pay (multiply hoursWorked by payrate, overtime included and 1.5 times payrate for hours > 40) equals() toString() Create a sub class of Employee called Sales with the following attributes: salesAmount : double //sales per week Type:…arrow_forward
- Create a project Vehicles in bluej. The project has Cars, Buses ,Trucks and Bikesclasses ,all these classes inherit from an interface Vehicle. Pedal_bikesand Motor_bikesare subclasses of abstract class Bikes. A.Show the relationship(class diagrams)between above mentioned classesand interfacesand write the necessary class definitions. B.Interface should have 3 methods: drive(), start() and stop(). C.abstract class Bikesshould have 2abstract methods: speed( ) and getModel( ). D.Which one of the following assignments are legal, why or why not? Justify. Pedal_bikes bik= new Motor_bikes( ); Vehiclev1 = new Buses (); Bikesbi= new Bikes( ) please use BlueJ program.arrow_forwardQ2. Write a program (Abstract+Interface) Define a class named Point containing: Two private instance variables x and y of type int. A full parametrized constructor Getters for all instance variables Define an abstract class named Shape containing: An instance variable named s of type Point. A full parametrized constructor A method named getS that returns the value of instance variable An abstract method named Area that has a return type double. Define an interface named Printable containing a method print without parameters and returning void. Define a class named Rectangle which is extended from class Shape, implements the interface printable and containing: Three instance variables named Length, Width of type int and an instance variable named d of type Point. A constructor with two parameters of type Point which initializes all the instance variables. The lengthis the difference in y-coordinates of any top and bottom point. length= Math.abs(s.getY()-d.getY()); The…arrow_forwardWrite a class named Person with data attributes for a person’s name, address, and telephonenumber. Next, write a class named Customer that is a subclass of the Person class. TheCustomer class should have a data attribute for a customer number, and a Boolean data attributeindicating whether the customer wishes to be on a mailing list. Demonstrate an instance of theCustomer class in a simple program.arrow_forward
- Create a base class with an abstract print( ) method that isoverridden in a derived class. The overridden version of themethod prints the value of an int variable defined in the derivedclass. At the point of definition of this variable, give it a nonzerovalue. In the base-class constructor, call this method. In main( ),create an object of the derived type, and then call its print( )method. Explain the results. (JAVA) Also provide clear output screenshots pleasearrow_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_forwardWhat is an abstract class? Choose only one option.(a) An object(b) A class with no methods.(c) A class with no concrete subclasses.(d) A class with at least one undefined message.(e) An interface.arrow_forward
- Create a class - Car, to contain all the properties a car must have, color, brand, and model. then create an instance of a Car type object to represent my specific car. then set the value of the properties defined in the class to describe my car, without affecting other objects or the class template. then reuse this class to represent any number of cars.arrow_forwardWhich (if any) of the following conditions are necessary for using polymorphism? Select all correct answers. The classes involved are in the same hierarchy. None of the classes can be abstract. All of the subclasses involved override the same method. The object reference cannot be of an interface type. An object reference of the superclass is used to call any methods. A superclass object is referenced by a subclass reference. Which of the following (if any) are true of abstract methods? Select all correct answers. Abstract methods must have a method body. Abstract methods cannot be declared in a class that isn't abstract itself. Abstract methods cannot be private or static. Abstract methods can only be declared in an interface. Abstract methods cannot be called. Constructor methods can be abstract.arrow_forwardWhat does the super keyword represents and where can it be used? Give an example of a superclass and subclass. Be sure to make all the instances variables of the super class private. Include at least one constructor in each class and ensure that the constructor of the subclass calls the constructor of the superclass. Also include a toString method in both classes that returns the values of the instance variables with appropriate labels. Ensure that the toString method of subclass calls the toString method of the superclass so that the string returned contains the values of all the inherited instance variables.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT