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: Polymorphism

  1. #1
    Junior Member
    Join Date
    Jun 2019
    Posts
    27
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Polymorphism

    My computeCommission is not working because I keep getting 0.0 instead of the actual commission value


    HTML Code:
    package lab4;
    
    public abstract class Policy {
    	
    	public double commission;
    	
    	public Policy(){
    		commission = 0.0;
    	}
    
    	public abstract void computeCommission();
    	
    	public double getCommission() 
    	{
    		return this.commission;
    	}
    	public void setCommission(double commission) 
    	{
    		this.commission = commission;
    	}
    
    	public String toString()
    	{
    		return "Commission: " + commission + "\n";
    	}
    	
    }
    HTML Code:
    package lab4;
    
    public class Auto extends Policy{
    	
    	String insured;
    	String make;
    	String model;
    	double liability;
    	double collision;
    	
    	public Auto(String insured_, String make_, String model_, double liability_, double collision_){
    		super();
    		insured = insured_;
    		make = make_;
    		model = model_;
    		liability = liability_;
    		collision = collision_;
    	}
    	public Auto(){
    		super();
    		insured = null;
    		make = null;
    		model = null;
    		liability = 0.0;
    		collision = 0.0;
    	}
    	public String getMake() {
    		return make;
    	}
    	public void setMake(String make) {
    		this.make = make;
    	}
    	public String getModel() {
    		return model;
    	}
    	public void setModel(String model) {
    		this.model = model;
    	}
    	public double getLiability() {
    		return liability;
    	}
    	public void setLiability(double liability) {
    		this.liability = liability;
    	}
    	public double getCollision() {
    		return collision;
    	}
    	public void setCollision(double collision) {
    		this.collision = collision;
    	}
    	@Override
    	public void computeCommission()
    	{
    		commission = (liability+collision)*1.30;
    	}
    	public String toString(){
    		String shapeString = super.toString();
    		return("AUTO INSURANCE POLICY" + "\n\t" + "Policy information includes: " 
    				+ "\n\tName: " + insured + "\n\tMake and Model: " + make + " " + model + "\n\tLiability: " + liability + "\n\tCollission: " + collision
    				+ "\n\t" + shapeString + "\n-------------------------------------------");
    	}
    	public String Error(){
    		return("Quit");
    	}
    
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Polymorphism

    What happened with the other questions you have posted on the forum?

    I keep getting 0.0
    Please post the program's output that shows what you are asking about.
    What variable has the 0.0 value? Is that variable ever assigned the desired value?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Polymorphism
    By gautammuktsar@gmail.com in forum Object Oriented Programming
    Replies: 1
    Last Post: March 5th, 2014, 03:15 PM
  2. Help with Inheritance and Polymorphism
    By jason3460 in forum Object Oriented Programming
    Replies: 5
    Last Post: October 2nd, 2013, 03:45 PM
  3. Not Understanding Polymorphism
    By superjacko in forum Java Theory & Questions
    Replies: 5
    Last Post: July 28th, 2013, 11:47 PM
  4. Inheritence and Polymorphism
    By Spanky_10 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 1st, 2013, 07:59 AM
  5. Polymorphism.
    By TP-Oreilly in forum Java Theory & Questions
    Replies: 2
    Last Post: March 11th, 2012, 09:28 AM

Tags for this Thread