Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Abstract class variable help

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Abstract class variable help

    The variable gross is still 0 after I gave it another number. Manager is a subclass of Employee and computePay is abstract. The gross in the toString method is 0. I tried to do gross = (pay/24); in the toString method of manager and it worked, but I need to put that in computePay and have it work there.

     import java.util.Scanner;
    import java.io.*;  
    import java.util.ArrayList; 
    public abstract class Employee
    {
       protected String name;
       protected double grossPay;
       protected double netPay;
       protected String job;
     
       public Employee(String person, String title)
       {
           name = person;
           job = title;
       }
       abstract public void computePay();
       public void computeTax()
       {
       }
       public String toString()
       {
           String s = "s";
           return s;
       }
     
    }

    public class Manager extends Employee implements Bonus
    {
     
        private String title;
        private double pay;
        private double gross;
        public Manager(String name, String title, String dprtmt, double salary)
        {
             super(name, title);
             gross = 0;
             pay = salary;
     
        }
     
        public double calcBonus()
        {
            return gross*0.01;
        }
        public void computePay()
        {
            gross = (pay/24);
        }
        public String toString()
        {
     
           String s = name + " title: " + job + " Pay: "+ Double.toString(pay) + " Gross: " +Double.toString(gross);
           return s;
        }
     
     
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,156
    My Mood
    Hungover
    Thanks
    141
    Thanked 595 Times in 510 Posts

    Default Re: Abstract class variable help

    If you want help, you'll have to provide an SSCCE that demonstrates exactly what you're doing. As of now, we have no idea how this code is being called, what the expected output is, or what the actual output is instead.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. What's difference between public class and abstract class?
    By Java95 in forum Java Theory & Questions
    Replies: 7
    Last Post: January 24th, 2012, 06:37 AM
  2. Multilevel inheritance of an abstract class
    By user2205 in forum Java Theory & Questions
    Replies: 1
    Last Post: September 27th, 2011, 05:00 PM
  3. Abstract class
    By jeskoston in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 26th, 2011, 01:46 PM
  4. abstract class
    By robinglow in forum Java Theory & Questions
    Replies: 2
    Last Post: August 20th, 2010, 01:36 AM
  5. abstract class
    By robinglow in forum AWT / Java Swing
    Replies: 2
    Last Post: August 20th, 2010, 01:36 AM