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
Related Tutorials/Questions & Answers:
Sub class of a previous java programSub 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
How to access sub class member using super class objectHow 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
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
Simple Java class program - Java BeginnersSimple
Java class program Hello,
Please help me, Write a simple
class that iterates through all the arguments passed in on the command line... java.util.Iterator;
public
class SimpleIterator{
public static void main(String args
Simple Java class program - Java BeginnersSimple
Java class program Hi sir,
Please help me Write a simple
class that iterates through all the arguments passed in on the command line...; Hi
import java.util.*;
import java.util.Iterator;
public
class J2ME Sub Menu - Java BeginnersJ2ME
Sub Menu I am creating a J2ME midlet in which I have created a menu by adding different commands in it. Now for example my command list is as follows
1. A
2. B
3. C
4. D
5. Exit
Now my question is I want to add
Sub-Editor for Java Magazine
Sub-Editor for
Java Magazine
... Description:
Sub Editor for a
Java Magazine,:
Sub-Editor who will work for our...;
Reference:
Sub Editor
Java Magazine
Please write back with detailed resume
Using Super class Variables With Sub-classed ObjectsUsing Super
class Variables With
Sub-classed Objects
... features of
java is that it is
follows a OOPs concept, and one of the feature of OOP in
java is that, we can
assign a subclass object or variable to the variable
Addition to my previous post - Java BeginnersAddition to my
previous post Addition to my
previous question about the address book
program.
I need to have separate classes:
CmdLineAddressBook.java
AddressBook.java
Contact.java
Address.java
Name.java
java classjava 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 classjava 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 classJava class What is the purpose of the Runtime
class Java httpservlet
Java httpservlet
HttpServlet
class is an abstract
class defined in "javax.servlet.http"
package and is
sub class of GenericServlet
class defined in "javax.servlet
Java Previous Iterator
Java previous Iterator function is present in the listIterator Interface... direction.
Java Previous Iterate Example
import java.util.ArrayList;
import java.util.ListIterator;
public
class previous {
public static void
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 Beginnersjava program m postin a
program...hv 2 create a
class,wid 6 data membr havin name,no,grade,n marks n 3
sub..........dere vil b 3 membr function.d...
sub)....n vil display it.....how 2 solve it?????plz reply.m a beginner..so facin
Java Abstract Class
Java Abstract
Class
...;
--or--ADS_TO_REPLACE_1
Java provides a special type of
class called...
class contains abstract methods.
Program can't instantiate an abstract
class ModuleNotFoundError: No module named 'sub'ModuleNotFoundError: No module named '
sub' Hi,
My Python
program is throwing following error:
ModuleNotFoundError: No module named '
sub'
How to remove the ModuleNotFoundError: No module named '
sub' error
Java program to get class name without package
Java program to get
class name without package ... example which
describes you that how you can get the
class name without package. For this
purpose we have to fetch first the full
class name with package
java programjava program
java program to implement the reflection of a particular
class details like constructor,methods and fields with its modifiers
java programjava 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 PROGRAMJAVA PROGRAM To write a
java prograam to create a employee
class, full time employee
class, part time employee
class using inheritance
Java ProgramJava 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 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 programjava program wap to show concept of
class in
java Java Bytebuffer
Java Bytebuffer
ByteBuffer is one of the
sub class of abstract
class Buffer in the "nio"
package.
Buffer
class has subclasses for each non-boolean primitive
java programjava 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
How to Read file line by line in Java program in
Java using Scanner
Class:
Besides the Buffer reader, using Scanner
class...
by line in
Java. But there are various ways that can help read a larger file... having less amount of memory.
In the example of
Java Read line by line below
java programjava 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 programjava 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 programjava program Create a washing machine
class with methods as switchOn, acceptClothes, acceptDetergent, switchOff. acceptClothes accepts the noofClothes as argument & returns the noofClothes
Java programJava 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 programJava 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 programJAva 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
abstract class and overriding - Java Beginners abstract
class and overriding?
Interface?
Give some example
program?
Hi friend,
Abstract
class :
In
java programming language, abstract classes... methods, which has to be implemented by
sub classes.
*)Abstract
class is a
Class java programjava 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 programJava 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 programJava 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
java programjava 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