Results 1 to 3 of 3
  1. #1
    lilac87 is offline Member
    Join Date
    Jul 2009
    Posts
    8
    Rep Power
    0

    Default Help with arrays!

    I am trying to write a code with parallel arrays. I'm not sure where I'm going wrong. Please help.

    THIS IS WHAT I'M TRYING TO DO:

    I am trying to create an application for a family who pays allowance to their children based on age, and if he/she has a job. The application will first ask for names and ages. Then prompt the user to enter if any of the children over 14 years or older have a job; however, the question will not be asked for any child under the age of 14.
    Conditions:
    · Kids under 8 = No allowance
    · Kids between 8 and 11 receive $5/week
    · Kids between 12 and 17 receive $10/week if they do not have an outside job.

    At the end, there will be a summary that includes:
    · A list of the children’s names and their corresponding allowance
    · The number of children that hold a job

    HERE'S WHAT I'VE GOT SO FAR:




    import javax.swing.JOptionPane;
    public class allowance {

    static final int MAX= 10;
    static final int MIN= 5;
    static final int N=0;

    public static void main (String[]args)
    {
    String [] Name;
    int [] Age;
    boolean [] Job;
    boolean Another;
    int Allowance,NumWorking;

    do{
    Name=enterName();
    Age=enterAge();
    Another=JOptionPane.showConfirmDialog("Another child in the family?");}
    while(Another==JOptionPane.YES_OPTION);
    Job=jobChild();
    Allowance=calcAllowance(Name,Age);
    NumWorking+=calcWorking(Age,job);
    Statement(Name, Allowance, numWorking);
    }

    private static String [] enterName ()
    {
    String [] name = new int [20];
    for (int i = 0; i < 20; i++)
    name[i] = JOptionPane.showInputDialog ("Enter name of child #1");
    return name;
    }
    private static int enterAge()
    {
    int [] age = new int [18];
    age=Integer.parseInt(JOptionPane.showInputDialog(" How old is ?"));
    while (age > 0 || age < 18) JOptionPane.showInputDialog("Error!\nAge must be between 0-18");
    return age;
    }
    private static boolean jobChild(String[] name)
    {
    job=JOptionPane.showConfirmDialog("Does"+name+"hav e a job?");
    return job;
    }
    private static int calcAllowance(String [] name,int age,boolean job){
    int allowance;
    if(age < 8)
    allowance = N;
    else if(age >8 || age < 11)
    allowance = MIN;
    else if(age > 12 || age < 17){
    switch(job){
    case JOptionPane.YES_OPTION: allowance=N;
    case JOptionPane.NO_OPTION: allowance=MAX;}
    return allowance;
    }

    public static void Statement(String [] name,int allowance,int numWorking){
    Integer.parseInt(JOptionPane.showMessageDialog(nul l, "Allowance:\n"+name[i]+allowance));

    }}

  2. #2
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    you're really gonna need to state a specific problem you're having.

    it's nice that you supplied us with code and what you need to do since some people tend to only do one or the other, but its really inefficient trying to decipher the difference between what you haven't done yet, what you're in the process of doing, what you've finished, etc.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by emceenugget View Post
    you're really gonna need to state a specific problem you're having.
    This is must lol. I don't why people not care of this.

Similar Threads

  1. A little help with arrays..
    By zeppelin in forum New To Java
    Replies: 8
    Last Post: 01-05-2009, 12:33 PM
  2. Help!! With arrays
    By ookie833 in forum New To Java
    Replies: 8
    Last Post: 12-14-2008, 12:57 AM
  3. Arrays
    By TheRocket in forum New To Java
    Replies: 6
    Last Post: 12-10-2008, 06:00 PM
  4. Need help with 2D arrays...
    By rrsv2 in forum New To Java
    Replies: 3
    Last Post: 11-30-2008, 03:15 AM
  5. 2D-Arrays
    By kbyrne in forum New To Java
    Replies: 1
    Last Post: 02-07-2008, 10:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •