Wrox Programmer Forums
|
BOOK: Java Programming 24-Hour Trainer by Yakov Fain
This is the forum to discuss the Wrox book Java Programming 24-Hour Trainer by Yakov Fain; ISBN: 978-0-470-88964-0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Java Programming 24-Hour Trainer by Yakov Fain section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 9th, 2011, 01:49 PM
Registered User
 
Join Date: Jun 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Lesson 3 Method Overriding.

I have the TestTax class;

Code:
class TestTax {
	public static void main (String[] args){
		NJTax t = new NJTax();
		
		t.grossIncome= 50000;
		t.dependents= 2;
		t.state= "NJ";
		
		double yourTax = t.calcTax();
		double totalTax = t.adjustForStudents(yourTax);
		
		System.out.println("Your tax is " + yourTax);
	}
}
Code:
class tax {
	double grossIncome;
	String state;
	int dependents;
	
	public double calcTax(){
		double stateTax = 0;
		if(grossIncome < 30000){
			stateTax = grossIncome * 0.05;
		}
		else{
			stateTax = grossIncome * 0.06;
		}
		return stateTax;
	}
	
	public void printAnnualTaxReturn(){
		// code goes here
	}
}
Code:
public class NJTax extends tax{
	double adjustForStudents (double stateTax){
	double adjustedTax = stateTax - 500;
	return adjustedTax;
	
		public double calcTax(){
			
		}
	
	}
}
I am having trouble with the Lesson requirement to:
"Change the functionality of calcTax( ) by overriding it in NJTax. The new version of calcTax( ) should lower the tax by $500 before returning the value."

How is this accomplished. I just have safaribooksonline and no videos for the solution.
 
Old June 16th, 2011, 05:11 PM
Registered User
 
Join Date: Jun 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

in your class for TestTax look at the println: ("Your tax is " + yourTax);

Try ("Your tax is " + totalTax);

That is the one you are using for the NJTax override.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Lesson 5 exercises. thelemur BOOK: Java Programming 24-Hour Trainer by Yakov Fain 9 March 29th, 2013 11:56 PM
Lesson 6 Try It zavodney BOOK: Stephens' Visual Basic Programming 24-Hour Trainer 2 June 6th, 2011 10:07 PM
Lesson 3 question soneal777 BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer 1 August 30th, 2010 06:17 PM
new keyword vs method overriding anand_instra C# 1 April 30th, 2008 01:46 PM
Overriding the ispostback method Indo77 ASP.NET 1.0 and 1.1 Basics 3 April 6th, 2005 02:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.