Sub class of a previous java program
Create a Faculty subclass of Employee which has the additional data of rank and expertise. Rank could be one of Assistant Professor, Associate Professor, or Professor. Expertise would be a String such as ?Computer Science?, ?Music?, ?History? etc. Create a Staff subclass of Employee which has the additional data of Category (Full or Part time). Provide suitable constructors for your classes. Each of these sub classes must have a changestatus() method that changes the rank or category respectively. For example, an Associate Professor could be promoted to Professor; a Full time classified could be demoted to part time. Add a changestatus() method to the Employee base class that simply outputs a message ?Cannot change this Employee?s status?.
Demonstrate dynamic binding in your main program. Declare an array of Employees (compile time type) but assign different subclasses to each array element (run time type). Show that getinfo() and changestatus() uses the methods determined by their run time types and displays all the relevant data.
The previous java program is this,
import java.util.*;
class EmployeeSalaries {
static Scanner input = new Scanner(System.in);
String name;
static int amt,sal=0;
EmployeeSalaries(String name, int sal) {
this.name = name;
this.sal = sal;
}
public void setName(String name){
this.name=name;
}
public static void setSal(int sal){
sal=sal;
}
static int increase() {
System.out.print("Enter amount to increase:");
amt = input.nextInt();
if (amt < 0) {
System.out.println("Invalid Amount");
return 1;
}
sal = sal + amt;
return 0;
}
static int decrease() {
System.out.println("Your Balance=" + sal);
System.out.print("Enter amount to decrease:");
amt = input.nextInt();
if (sal < amt) {
System.out.println("Not sufficient balance.");
return 1;
}
if (amt < 0) {
System.out.println("Invalid Amount");
return 1;
}
sal = sal - amt;
return 0;
}
void getInfo() {
System.out.println("Name:" + name);
System.out.println("Balance:" + sal);
}
void quit() {
EmployeeSalaries.setSal(0);
}
void salarychange(){
int menu;
System.out.println("1. Increase Salary Amount");
System.out.println("2. Decrease Salary Amount");
boolean quit = false;
System.out.print("Please enter your choice: ");
menu = input.nextInt();
switch (menu) {
case 1:
EmployeeSalaries.increase();
break;
case 2:
EmployeeSalaries.decrease();
break;
}
}
public static void main(String args[]) {
System.out.println("Enter your Name: ");
String nn = input.nextLine();
System.out.println("Enter Initial Salary: ");
int sal = input.nextInt();
EmployeeSalaries b1 = new EmployeeSalaries(nn,sal);
b1.salarychange();
b1.getInfo();
}
}
View Answers
Ads
Related Tutorials/Questions & Answers:
Sub class of a previous java program
Sub class of a
previous java program Create a Faculty subclass...
java program is this,
import java.util.*;
class EmployeeSalaries...). Provide suitable constructors for your classes. Each of these
sub classes must have
Sub-class in java
Sub-
class in
java
 ...
class and subclass.
-- Inheritance
allows a new
class known as the
sub-
class... promotes the concept of code reusability and
saves a lot of time.
--
Sub class
Advertisements
Class Average Program
Class Average
Program
This is a simple
program of
Java class. In this
tutorial we will learn how to use
java program for displaying average value. The
java instances
How to access sub class member using super class object
How to access
sub class member using super
class object
class A{
}
class B extends A{
int b=1;
}
class Test{
public static void main(String args[])
{
what to do here to access
sub class variable b using super
class object
java class
java class write a
java program to display a msg "window closing" when the user attempts to close the window.(a) create a window
class (b) create frame within the window
class (c) extends window adapter
class to display the msg
java class
java class please send me the answer of the question which i have send according of
java class assoon as possible . Write a
java program to display....
a. Create a window
class. b. Create frame within the window
class.
c. Extend
java program
java program
java program to implement the reflection of a particular
class details like constructor,methods and fields with its modifiers
a java program
a
java program Write a
java program that accepts positive numbers... of entered numbers. The sentinel value
(the last value that differs from the
previous... through the link may, this will be helpful for you
http://www.roseindia.net/
java
java program
java program write a
java program which shows how to declare and use STATIC member variable inside a
java class.
The static variable are the
class variables that can be used without any reference of
class.
class
java program
java program wap to show concept of
class in
java
JAVA PROGRAM
JAVA PROGRAM To write a
java prograam to create a employee
class, full time employee
class, part time employee
class using inheritance
Java Program
Java Program I want to Write a
program in
JAVA to display to create a
class called MATRIX using a two-dimensional array of integers. Perform the addition and subtraction of two matrices.
Help me
Java - Class, Object and Methods in Java
Java -
Class, Object and Methods in
Java
 ... will see how to use the
class, object and it's methods.
This
program uses.... In this
program there are two classes has been used except the
main
class in which
java program
java program write a
java program to read a file content into a string object using available and read methods of
java bufferedinputstream.
Please visit the following link:
http://www.roseindia.net/
java/example/
java
java program
java program write a
java program to add or substract days in current date and time value using
JAVA calender
class.
Add Days
import java.util.*;
public
class AddDaysToDate {
public static void main(String
java program
java program You need to keep record of under- graduate, PhD students, faculty and staffs
of your institute.
Write an abstract
class Person...: String
3. Method Get_info() returns information of the person
Extend
class
Java program
Java program Write a
Java program that demonstaress multiple inheritance.
Java does not support Multiple Inheritance but you can show... IntefaceA,InterfaceB {
void method3();
}
class InterfaceExample implements
Java program
Java program Write a
Java program that takes 3 integer numbers from...;
Java display maximum number using conditional operator:
import java.util.*;
class Greatest
{
public static void main(String[] args)
{
Scanner
JAva program
JAva program Write a
JAva program that takes various string from command line and display them in sorted order.
Java display strings in sorted order:
import java.util.*;
class ArraySort{
public static void main
java program
java program Create a washing machine
class with methods as switchOn, acceptClothes, acceptDetergent, switchOff. acceptClothes accepts the noofClothes as argument & returns the noofClothes
java program for
java program for
java program for printing documents,images and cards
Java program
Java program Write a
Java program that tales filename or directo;ry... of files in that directory.
Java Check File
import java.io.*;
import java.util.*;
class CheckFile
{
public static void main(String[] args
java program
java program my array size is 10, then how can i identify
class A object from array.
Q) how jvm know a particular object is serialize
java program
java program write a
program showing two threads working... "show the tikect")
import java.io.*;
class Theater{
public static...);
t1.start();
t2.start();
}
}
class MyClass implements Runnable
java program
java program (1) WAP in
java to take input of int,string,float and print them (use scanner
class)?
Sample output-
Enter an int : 10
Enter a string... of a circle and calculate area?
formula=pirr (use math
class)
sample output
Java program
Java program Write a
java program which reads in a file, whose name is given by the user ,and o perform the following tasks:-
ΓΆβ?¬ΒΆ To read data... for all persons in an array of objects using Tokenizer
class to separate data
a Java program
a
Java program
Write a
Java program to print even numbers from 2 to 1024?
Write a
Java program to print ? My Name is Mirza? 100 times?
Write a
Java program to print Fibonacci Series?
Write a
Java program to reverse a number
java program
java program how to write an addition
program in
java without using arithematic operator