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

Thread: End of line error.

  1. #1
    Member
    Join Date
    Oct 2012
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default End of line error.

    I have this assignment I need to do using an array. I get this error at the end of the line containing the array.

    public class UseTaxPayer
    {
           public static void main(String[] args)
           {     
                  TaxPayer Payer = new TaxPayer(10000.00, 1);
                  {
                  int [] TaxPayer = new int [10]
                  for(long inc = 0; inc < TaxPayer; inc++)
                  {
                         System.out.println("SSN = " + (inc + 1) + " Income = " + income);
                         income = (income + 10000);
                  }
                  }     
              }
    }

    I'm not sure why. Inserting a semi colon also gives an error. Any help would be nice. Thank you.


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: End of line error.

    inc < TaxPayer;

    How large of an integer is TaxPayer

    In the future please copy-paste error messages, as the exact wording is very important. Not all errors are as sore thumb as this one.



    I'm not sure why. Inserting a semi colon also gives an error.
    Probably because there is not one missing. Depends on where you put it.

  3. #3
    Member
    Join Date
    Oct 2012
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: End of line error.

    I know I should've included the errors exactly as they were, but they were very confusing to me for some reason, I ended up changing my entire program around. I have two classes. Here's the entire program:

     
    public class TaxPayer
    {		
    		private long social;
    		private double income;
            public TaxPayer()
            {
                   social = 1;
                   income = 0;
            }
            public long GetSocial()
            {
                   return social;
            }
            public void SetSocial(long SSN)
            {
                   social = SSN;
            }
            public double GetIncome()
            {
                   return income;
            }
            public void SetIncome(double money)
            {
                   income = money;
            }
    }
     
     
    public class UseTaxPayer
    {
            public static void main(String[] args)
            {	
            	TaxPayer First = new TaxPayer();
            	double income = First.GetIncome();
            	long SSN =  First.GetSocial();
                int[] TaxArray = new int[10];
                double Total = income;
                for(int x = 0; x < TaxArray.length; x++)
                {    
            	   System.out.println("SSN = " + SSN + " Income = $" + Total + "0");   
            	   SSN++;
                       Total = (income + Total);
                }      
     
            }
    }

    I now have a different problem. As my program runs the income is supposed to be raised by 10,000 each time, however the variable seems to remain the same each time. Any idea how I can fix this?

    I'm going to continue tinkering with it, but I do need the help. I'm also worried I may not be satisfying the entire assignment, but I'll cross the bridge once I get this working, cause it's the closest I've gotten all week. I know this should be easy as pie, but I'm really struggling with the class for some reason...Apparently Trig and Java just aren't my things, and the one assignment a week isn't really enough practice, well one assignment plus tutorial assignments which are really just copy out of the book and into the computer but I'm trying to comprehend it all. Thank you for your help again.

    Edit:
    Right I fixed my incrementing problem, it should've read Total = (income + Total); vice Total = (income + 10000); it now increments properly. Now onto the question of whether I've done what is asked in the assignment. Because the way I read it, it makes no sense, but perhaps I'm incorrect in that assumption.

    The Assignment reads as follows

    The purpose of this assignment is to use arrays and loops. It is based on a problem from Java Programming by Joyce Farrell.

    Create a class called Taxpayer. This will be a class from which objects will be instantiated (i.e. no main method). Also create a UseTaxpayer class. Include a main method in this class. The UseTaxpayer class will be the class where you instantiate 10 Taxpayer objects.
    The Taxpayer class will have two private variables - a long for the social security number (SSN) and a double for the annual income. Create a Taxpayer constructor that accepts arguments for the SSN and the income. Also create get/set methods for both class variables.
    In the UseTaxpayer class, create an array of 10 Taxpayer objects. Instantiate the 10 Taxpayer objects using the constructor that requires values for SSN and income. Use 1 to 10 for the SSN values and 10000 (10,000) to 100000 (100,000) for the income respectively. That is, the first taxpayer will have a SSN of 1 and an income of 10000. The tenth taxpayer will have a SSN of 10 and an income of 100000. You must use a looping statement to call the constructor for the Taxpayer objects.
    Print the values from your Taxpayer array objects in the UseTaxpayer class. (Sample output). You must print the values from the array in a separate method (separate from main). You must pass the Taxpayer array as an argument to this method.
    Use the length instance variable for all loop control conditions.
    The UseTaxpayer class cannot have any "class-wide" variables except symbolic constants. This means all your variables in the UseTaxpayer class must be defined within a method.
    This project is worth a maximum of 30 points if received by the deadline. Check the class syllabus for the penalties for submitting an assignment late. Check the online calendar for the exact due date if you are in an online section of this class. Check the class syllabus for the exact due date if you are in an on-campus section of this class.


    The output should read like this:
    SSN = 1 Income = $10000.00
    SSN = 2 Income = $20000.00
    SSN = 3 Income = $30000.00
    SSN = 4 Income = $40000.00
    SSN = 5 Income = $50000.00
    SSN = 6 Income = $60000.00
    SSN = 7 Income = $70000.00
    SSN = 8 Income = $80000.00
    SSN = 9 Income = $90000.00
    SSN = 10 Income = $100000.00

    which mine does as above.
    However, as the assignment reads, it seems like I should be having a constructor in the first class as I do above, however instead of initializing the array like I have, It should be an array like

    [highlight = java]
    int[] TaxPayers = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}:
    int[] Income = {10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 10000};
    [/highlight]

    However if I did it like this, I'd be asking for the print out to be printing Income[x] etc, (whatever is in placeholder 0, 1, 2 etc etc) which would, I feel, negate the purpose of having a constructor in one class, and an array in the next?

    Is this a correct assumption and I've written my code incorrectly? I understand there's different ways of writing code for things, but I don't feel like I'm doing what the assignment asks however I feel the assignment makes no sense the way it's written?
    Last edited by Sylis; October 27th, 2012 at 08:44 PM. Reason: Fixed it.

Similar Threads

  1. Replies: 10
    Last Post: September 16th, 2011, 07:49 PM
  2. 2 questions(an error and line breakpoint?)
    By derekxec in forum What's Wrong With My Code?
    Replies: 13
    Last Post: July 22nd, 2011, 06:14 PM
  3. How can I detect the end of a line in a file ?
    By lumpy in forum Java Theory & Questions
    Replies: 3
    Last Post: February 18th, 2010, 02:13 AM
  4. Reading a file line by line using the Scanner class
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: April 17th, 2009, 07:34 AM
  5. How to Read a file line by line using BufferedReader?
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: May 19th, 2008, 06:32 AM