Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


will smith
Sub class of a previous java program
0 Answer(s)      2 years and 8 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();

        }
}

Advertisement
View Answers

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
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
ARRAY SUB - Java Interview Questions
ARRAY SUB  What Is A Sub Array ?I Want defination ?How To Declare Sub Array
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
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 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 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
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
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
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
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
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
Date Next and Previous - Java Interview Questions
java.util.*;import java.text.*; public class StringToDate{ public static void main
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
to display NEXT and previous option after 10 entries in java
to display NEXT and previous option after 10 entries in java  As after jsp code we refer to java for connectivity and i want that directly only 10... in java?   Please visit the following link: Java Pagination  
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 class
Java class  What is the purpose of the Runtime class
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
What is the Sub-Query?And what is the properties of Sub-Query?
What is the Sub-Query?And what is the properties of Sub-Query?  What is the Sub-Query?And what is the properties of Sub-Query?   Hi, Sub-queries are often referred to as sub-selects, as they allow a SELECT statement
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
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
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
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
java program
java program  java program to implement the reflection of a particular class details like constructor,methods and fields with its modifiers
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
write a program to demonstrate wrapper class and its methods......
write a program to demonstrate wrapper class and its methods......  write a program to demonstrate wrapper class and its methods
Java Program - JDBC
Java Program  A java program that display data in textfields and having buttons for move next, move previous,move last,move first using JFrame
Advertisements
 

 

 

DMCA.com