473,385 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Java help! - Arrays

Windows XP
JAVA

n00b here. I'm not very good at Java. In fact I am really struggling with it. I've spent the last 6 hours trying to get this to work. The book I have isn’t very helpful.

I'm supposed to create a class names Taxpayer. Data fields for Taxpayer include Social Security number (use an int for the type, and do not use dashes within the Social Security number) and yearly gross income. Methods include a constructor that requires values for both data fields, and two methods that each return one of the data fields values. Write an application named UseTaxpayer that declares an array of 10 Taxpayer objects. Set each Social Security number to 999999999 and each gross income to zero. Display the 10 Taxpayer objects.
Save the files as Taxpayer.java and UseTaxpayer.

here is the code I have written so far. I seem to have hit a wall. I'm not even sure if I went the correct course. Any suggestions?

thanks

Expand|Select|Wrap|Line Numbers
  1. public class Taxpayer 
  2. {
  3.     private int socNum;
  4.     private double yearIncome;
  5.  
  6.     public Taxpayer(int s, int i)
  7.     {
  8.         socNum = s;
  9.         yearIncome = i;        
  10.     }
  11.     public int getSocNum()
  12.     {
  13.         return socNum;
  14.     }
  15.     public double getYearIncome()
  16.     {
  17.         return yearIncome;
  18.     }
  19.  
  20. }
  21.  
Expand|Select|Wrap|Line Numbers
  1. public class UseTaxpayer
  2. {
  3.     public static void main(String[] args)
  4.     {
  5.         Taxpayer[] aTaxpayer = new Taxpayer[10];
  6.  
  7.  
  8.  
  9.  
  10.  
  11.     }
  12. }
  13.  
Nov 12 '07 #1
3 3131
Laharl
849 Expert 512MB
Everything looks fine so far. Do you know how to use for or while loops?
Nov 12 '07 #2
r035198x
13,262 8TB
Windows XP
JAVA

n00b here. I'm not very good at Java. In fact I am really struggling with it. I've spent the last 6 hours trying to get this to work. The book I have isn’t very helpful.

I'm supposed to create a class names Taxpayer. Data fields for Taxpayer include Social Security number (use an int for the type, and do not use dashes within the Social Security number) and yearly gross income. Methods include a constructor that requires values for both data fields, and two methods that each return one of the data fields values. Write an application named UseTaxpayer that declares an array of 10 Taxpayer objects. Set each Social Security number to 999999999 and each gross income to zero. Display the 10 Taxpayer objects.
Save the files as Taxpayer.java and UseTaxpayer.

here is the code I have written so far. I seem to have hit a wall. I'm not even sure if I went the correct course. Any suggestions?

thanks

Expand|Select|Wrap|Line Numbers
  1. public class Taxpayer 
  2. {
  3.     private int socNum;
  4.     private double yearIncome;
  5.  
  6.     public Taxpayer(int s, int i)
  7.     {
  8.         socNum = s;
  9.         yearIncome = i;        
  10.     }
  11.     public int getSocNum()
  12.     {
  13.         return socNum;
  14.     }
  15.     public double getYearIncome()
  16.     {
  17.         return yearIncome;
  18.     }
  19.  
  20. }
  21.  
Expand|Select|Wrap|Line Numbers
  1. public class UseTaxpayer
  2. {
  3.     public static void main(String[] args)
  4.     {
  5.         Taxpayer[] aTaxpayer = new Taxpayer[10];
  6.  
  7.  
  8.  
  9.  
  10.  
  11.     }
  12. }
  13.  
In your TaxPayer class you declared yearIncome as double but you are trying to assign an int to it.
Your array declaration in the UseTaxpayer class is fine.
You now need a for loop to go through each element position in the array and assigning the new Taxpayer objects.
Nov 12 '07 #3
ok I got it to work. thanks for the help. but now problem # 2. I need to modify the UseTaxpayer application so each Taxpayer has a successive Social Security number from 1 top 10 and a gross income that ranges from $10,000 to $100,000, increasing by $10,000 for each successive Taxpayer. Save as UseTaxpayer2

Here is what I have so for far from the UseTaxpayer application. Any suggestions on how to get it to increment?

Expand|Select|Wrap|Line Numbers
  1. public class Taxpayer 
  2. {
  3.     private int socNum;
  4.     private int yearIncome;
  5.  
  6.     public Taxpayer(int s, int i)
  7.     {
  8.         socNum = s;
  9.         yearIncome = i;        
  10.     }
  11.     public int getSocNum()
  12.     {
  13.         return socNum;
  14.     }
  15.     public int getYearIncome()
  16.     {
  17.         return yearIncome;
  18.     }
  19.  
  20. }
  21.  
and

Expand|Select|Wrap|Line Numbers
  1. public class UseTaxpayer
  2. {    
  3.     public static void main(String[] args)
  4.     {    
  5.      Taxpayer[] aTaxpayer = new Taxpayer[10];
  6.  
  7. for(int i = 0; i < 10; i++)
  8.             aTaxpayer[i] = new Taxpayer(999999999,0);
  9.             for(int i = 0 ; i < 10; i++)
  10.             {
  11.     System.out.println(aTaxpayer[i].getSocNum()
  12.                 + " " + aTaxpayer[i].getYearIncome());
  13.  
  14.             }
  15.         }
  16. }
  17.  
Please do not double post. Post any replies here
Locking this thread.
Nov 12 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: James Hong | last post by:
Help please, I try to sending an email from my html page using the java applet. but it give error on most of the PC only very few work, what is the error i make the java applet show as below ...
0
by: Shawn | last post by:
I am getting the following error with a Java Applet being served out by IIS over HTTPS/SSL using a Verisign certificate: java.lang.NoClassDefFoundError: javax/help/HelpSetException at...
0
by: Martin | last post by:
Hi All, I am a relative newbie to Java / Applets, but am despirately after some help ! I have got the following code, which is basically a listing with button items along the sides, allowing...
16
by: Thomas G. Marshall | last post by:
This message is sent to these newsgroups because they are no longer valid: comp.lang.java comp.lang.java.api comp.lang.java.bugs comp.lang.java.misc comp.lang.java.setup comp.lang.java.tech
37
by: asj | last post by:
awhile back, eBay decided to switch from a Microsoft/.NET/Windows architecture on the backend to a J2EE one, which might explain why their java backend will handle up to 1 BILLION page views a day!...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
0
by: daniel li | last post by:
I got another convert issue. This is the same project as I posted yesterday, and received a perfect response. The conversion threw a SupportClass for me and one of the data type is...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
6
by: Rhino | last post by:
I'm trying to debug a simple Java UDF written in the DB2General style within Eclipse. I'm getting a java.lang.UnsatisfiedLinkError when I execute the set() method in the UDF. I know that the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.