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 6 of 6

Thread: First, simple, two-classed tax program

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default First, simple, two-classed tax program

    Hi all,

    I'm entering into a programming course next September and am trying to get the essentials of Java before hand. I attempted to create my first program but have learned that it's much easier when you can speak to someone who knows what they're doing. Anyway, here is my code:

     
    public class Taxone {
     
    	//naming variables
    	double income;
    	String state; 
    	int dependants;
     
    }

     
    public class Taxtwo {
     
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO creating instance of a variable
     
    		Taxone t = Taxone;
     
    		t.income = 1000000;
    		t.state = NY;
    		t.dependants = 4;
     
    		{
     
     
    		public double t.calctax();
    		stateTax=0;
    		if (income > 999999){
    			stateTax=income*0.75;
    			{
    			else stateTax=income*0.0001;
    			}
    		}
    			return stateTax;
     
    	 double yourTax = t.calctax();
     
    	System.out.println("Your tax is" yourTax);

    My Error

    I get an error that says I cannot invoke primitive type double on the t.calctax method in the last few lines of class 2, and consequently the yourTax variable is invalid on the last line.

    Help mucho appreciado.


  2. #2
    Member vanDarg's Avatar
    Join Date
    Jan 2011
    Location
    Chicago
    Posts
    65
    My Mood
    Mellow
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default Re: First, simple, two-classed tax program

    What are you trying to accomplish? And please use code tags
    "Everything should be made as simple as possible, but not simpler."
    Asking Questions for Dummies | The Java Tutorials | Java Coding Styling Guide

  3. #3
    Junior Member
    Join Date
    May 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: First, simple, two-classed tax program

    Quote Originally Posted by vanDarg View Post
    What are you trying to accomplish? And please use code tags
    What I thought I would accomplish was to create a few variables in the first class, and then define them in the second class and create a simple method in the second class to give me a final value.

    Class One
    public class Taxone {
     
    	//naming variables
    	double income;
    	String state; 
    	int dependants;
     
    }

    Class Two
     
    public class Taxtwo {
     
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO creating instance of a variable
     
    		Taxone t = Taxone;
     
    		t.income = 1000000;
    		t.state = NY;
    		t.dependants = 4;
     
    		{
     
     
    		public double t.calctax();
    		stateTax=0;
    		if (income > 999999){
    			stateTax=income*0.75;
    			{
    			else stateTax=income*0.0001;
    			}
    		}
    			return stateTax;
     
    	 [COLOR="red"]double yourTax = t.calctax();[/COLOR]
     
    	System.out.println("Your tax is" [COLOR="red"]yourTax[/COLOR]);

    The errors are where I attempted to make the code red, the first says I can't use the double primitive there, the second says the yourTax variable is invalid.

  4. #4
    Member vanDarg's Avatar
    Join Date
    Jan 2011
    Location
    Chicago
    Posts
    65
    My Mood
    Mellow
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default Re: First, simple, two-classed tax program

    First, if you are trying to manipulate variables of the first class with methods, you should define those methods within the first class:
    public class Taxone {
     
    	//naming variables
    	double income;
    	String state; 
    	int dependants;
     
       // Define methdos here
    }
    Second, I'm not sure where your stateTax variable is coming from. I can't find where it is declared. Please look at my signature and click the link for the java tutorials. I would go through them all, but pay special attention to primitive data types as well as defining classes.
    "Everything should be made as simple as possible, but not simpler."
    Asking Questions for Dummies | The Java Tutorials | Java Coding Styling Guide

  5. #5
    Junior Member
    Join Date
    May 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: First, simple, two-classed tax program

    Quote Originally Posted by vanDarg View Post
    First, if you are trying to manipulate variables of the first class with methods, you should define those methods within the first class:
    public class Taxone {
     
    	//naming variables
    	double income;
    	String state; 
    	int dependants;
     
       // Define methdos here
    }
    Second, I'm not sure where your stateTax variable is coming from. I can't find where it is declared. Please look at my signature and click the link for the java tutorials. I would go through them all, but pay special attention to primitive data types as well as defining classes.
    Thanks very much, will check your tips out a bit later today.

  6. #6
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    471
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: First, simple, two-classed tax program

    If you get errors, please post the full error message text and stack trace (if present). Java errors usually tell you exactly what is wrong and where.

    To create a new instance of Taxone, you must use the 'new' keyword:
    Taxone t = new Taxone();
    I can see you appear to be trying to declare a public double in the middle of your 'main' method, but not only can you not do that (only member variables can have access specifiers like 'public', not local variables) it doesn't make sense, because you haven't named it:
    ...
    public double ?? t.calctax(); // ?? where's the variable name?
    ...
    You're also using local variables 'stateTax' & 'income' that you haven't declared, and calling a method 'calctax()' that doesn't exist, you're trying to return a value from 'main', which is a void method, plus you have a curly brace { that has no corresponding closing curly brace }, state value or variable NY is undefined (it could be "NY"), etc...
    Last edited by dlorde; May 24th, 2011 at 03:24 PM.

Similar Threads

  1. please help with simple program!!!
    By jokneez in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 14th, 2011, 11:42 AM
  2. urgent simple help for a very simple program
    By albukhari87 in forum Java Applets
    Replies: 4
    Last Post: June 5th, 2010, 04:43 PM
  3. simple program
    By Memb in forum Paid Java Projects
    Replies: 0
    Last Post: March 17th, 2010, 02:47 PM
  4. Simple Program for Cash
    By javastudent in forum Paid Java Projects
    Replies: 9
    Last Post: December 1st, 2009, 07:25 AM
  5. PLEASE HELP!!!! simple java program...
    By parvez07 in forum Object Oriented Programming
    Replies: 5
    Last Post: August 26th, 2009, 07:38 AM