Home Answers Viewqa Java-Beginners Sub class of a previous java program

 
 


will smith
Sub class of a previous java program
0 Answer(s)      a year and 2 months ago
Posted in : Java Beginners

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 Pages:
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
Output Previous or Next Day of the Month
class. The program is to prompt the user (both computer science and drug... or previous day: The program should output the next day's or previous day's date...Output Previous or Next Day of the Month   Please Help! I need
Some additions for my previous question - Java Beginners
, then use the Primes class to perform the calculation. The program should also...Some additions for my previous question  This is the question I posted several hours ago: "I'm trying to write a program that has a text field
Sub Namespace
Declaring sub-namespace: We all are familiar with the directory structure or the tree of the file and folders, similarly we can get the nested or sub... have done Java or C# before then this topic will be more easier. The following
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
Using Super class Variables With Sub-classed Objects
Using Super class Variables With Sub-classed Objects  ..., as well as the object references of class Rectangle. The code of the program... features of java is that it is follows a OOPs concept, and one of the feature
Addition to my previous post - Java Beginners
Addition 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
Date Next and Previous - Java Interview Questions
java.util.*;import java.text.*; public class StringToDate{ public static void main
ARRAY SUB - Java Interview Questions
ARRAY SUB  What Is A Sub Array ?I Want defination ?How To Declare Sub Array
Class
the class, object and it's methods. This program uses the several values... through the several objects created for the several class. In this program...; class_name object_name = new class_name(); Output of the program
abstract class
abstract class   Explain the concept of abstract class and it?s use with a sample program.   Java Abstract Class An abstract class is a class that is declared by using the abstract keyword. It may or may not have
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
Program
Program  Define an Abstract class DigitalCamera with instance variables like make, model, resolution, etc, and create() to set the details of camera. Use three sub classes for three different makes (eg. Canon, Olympus, Sony
Getting Previous, Current and Next Day Date
previous, current and next date in java. The java util package provides... C:\vinod\Math_package>java GetPreviousAndNextDate Previous... Getting Previous, Current and Next Day Date   
java program - Java Beginners
java 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
J2ME Sub Menu - Java Beginners
J2ME 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
Java Abstract Class
Java Abstract Class      ...;  --or-- Java provides a special type of class called an abstract class... to write the actual implementation code. An abstract class can be extended into sub
program
program  explanation of program on extending thread class   Hi Friend, Please go through the following link: Java Threads Thanks
program
is working in Java department and salary is 10000". Instantiate the Employee class...program  Create a class called Employee with member variables employeeId, employeeDept and employeeSalary. Create a method called setEmployeeDetails
Sub-Editor for Java Magazine
Sub-Editor for Java Magazine   ... Description: Sub Editor for a Java Magazine,: Sub-Editor who will work for our... for the role of Sub-Editor in our rapidly growing, newly launched e-magazine
Class in Java
Class in Java      ... structure. First of all learn:  what is a class in java and then move on to its... for constructing  java program: package package_name
PHP Previous Next Page - PHP
PHP Previous Next Page  PHP Previous Next PageIs it possible to create dynamic navigation using PHP and MYSQL? DO I need to create a class to create the next, previous buttons in PHP? I?m digging for a small as well as handy code
Simple Java class program - Java Beginners
Simple 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 Beginners
Simple 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
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
program - Java Beginners
the program : import java.io.*; class NumberProgram { public static void main...program  Hello..can u write the following program for me ..thanks 1. Write a program that reads three numbers and an integer n. The program
JPA Sub-Queries
JPA Sub-Queries       In this section, you will see how to use sub-queries in your JPA application. Sub-queries allows you for querying the vast number of data
how to sort the result of this 2 class program in java.....????
how to sort the result of this 2 class program in java.....????  package setget1_method; import java.util.Scanner; public class Main... setget1_method; class LBook { private String title; private String author; private int
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 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 Calculator Program
Java Calculator Program  Hi, so I need to make a program that "works... Class and need to implement the children classes, which are Number, Product, Sum... expressions will each have two (sub) expressions, a left hand side and a right hand side
Java Program - JDBC
Java Program  Write a Java Code using swings and display records from a table in ms access and display next,previous,last,first records by click... java.awt.event.*; import javax.swing.table.*; public class NavigateData extends
Zip Folder Using Java
in this folder are zipped by using java. Here we will learn how to compress files and sub folders of a folder just to take less space. To do so we create two objects of File class. In first object we are pass the name of  the folder
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  java program to implement the reflection of a particular class details like constructor,methods and fields with its modifiers
Java - StringBuffer class in Java
Java - StringBuffer class in Java   ... program. The StringBuffer class is used to represent characters that can... class. This example explains how you can use functions provided by the StringBuffer
create folders and sub folders based on excel data
create folders and sub folders based on excel data  Hi, i have... sub folders, the parent folder is same, so the parent column is null but i need to take the Bank value only. so how can i achieve this through java code
Java Bytebuffer
Java Bytebuffer       ByteBuffer is one of the sub class of abstract class Buffer in the "nio"... buffers. This class is also important for the use of channels in java. -- Absolute
Explain final class, abstract class and super class.
Explain final class, abstract class and super class.  Explain final class, abstract class and super class.   Explain final class, abstract class and super class. A final class cannot be extended. A final class
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 program
java program  wap to show concept of class in 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
for writting java program why we are taking more than one class
for writting java program why we are taking more than one class  for writting java program only one class is enough but why we are taking more than one class
source code in java for a program using class - Java Beginners
source code in java for a program using class  Dear sir/madam i want source code in java for following program: WAP which creates a class accountthat stores customer name,account number and type of account.From this derive
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 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 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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.