Results 1 to 8 of 8
  1. #1
    bamagirl31 is offline Member
    Join Date
    May 2011
    Posts
    47
    Rep Power
    0

    Default Help with arrays!!

    I have a question. Say I have an application and variables established. But the variables which have been established need to be put into arrays. How do I do this? One of the variables is used to calculate another variable. How do I form an array for these two? Thanks.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Can you give us more detail on just what it is you are trying to do? Is this an academic exercise? If so, have you been given certain instructions and constraints, and if so, can you post them here?

  3. #3
    bamagirl31 is offline Member
    Join Date
    May 2011
    Posts
    47
    Rep Power
    0

    Default Explanation

    Hi. I have an application set up with two variables such as x = term * 12; and y = rate /12; How can I set up term and rate with different amounts using an array if they are already initialized at 0? Can I set that up a different way? Thanks. I hope that better explains what I am attempting to do.

  4. #4
    bamagirl31 is offline Member
    Join Date
    May 2011
    Posts
    47
    Rep Power
    0

    Default

    Hi, basically the loan term and interest rate will vary but they are used to obtain other values. I do not know where I am going wrong.

    package mortgages;

    /**The Mortgage class implements an application which calculates the mortgage
    *payment, interest paid, principal paid and loan balance.
    * The application prints interest paid, mortgage payment, and loan balance
    * to output
    * @author Lekeisha
    **/
    import java.io.IOException;
    public class Mortgages
    /**Creates a new instance of Mortgage**/
    {

    public static void main(String[] args)
    {
    double[]loanTerm = {7, 15, 30};
    double[]intRates = {.0535, .0550, .0575};//initiates the monthly interest rate
    calmonintrate(intRates);
    caltotmons(loanTerm);
    }
    public static void calmonintrate(double intRates[])
    {
    for(int counter = 0; counter<intRates.length;counter++)
    intRates[counter]/12;
    }
    public static void caltotmons(double loanTerm[])
    {
    for(int counter = 0; counter<loanTerm.length;counter++)
    loanTerm[counter]*12;
    }


    monPay = amLoanOne*monIntRate/(1-(Math.pow((1+monIntRate), (-totMons))));
    //calculates the mortgage payment
    intsPaid = amLoanOne*monIntRate;
    //calculates the interest paid

    princPaid = monPay - intsPaid;
    //calculates the principal paid
    amLoanNxt = amLoanOne - princPaid;
    //calculates the amount of loan balance after initial amount



    for(int i = 0; i < 31; i++)
    {
    intsPaid+=i;//counter for interest paid
    princPaid+=i;//counter for principal paid
    amLoanNxt+=i;//counter for amount of loan balance after initial amount

    System.out.println("Interest amount is $" + Math.round(intsPaid)+ ".");
    //calculates the interest paid with interest rate of 5.75%
    System.out.println("Mortgage payment amount is $" + Math.round(monPay)+ ".");
    //calculates the mortgage payment amount
    System.out.println("Loan balance amount is $" + Math.round(amLoanNxt)+ ".");
    //calculates the loan balance
    System.out.println("(press Enter to exit)");
    //asks user input of 'Enter' to display other lines of text
    try
    {
    System.in.read();//reads user input
    }
    catch (IOException e)
    {
    return;

    }
    }
    }
    }

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,459
    Rep Power
    25

    Default

    PLEASE add code tags to your code to preserver formatting. It is hard to see where matching { and } are. Some of your code appears to be outside of any method.

    I do not know where I am going wrong.
    Can you explain? If the output is incorrect, please show what the current output is and explain the problem with it and show what it should be.

    How can I set up term and rate with different amounts using an array if they are already initialized at 0?
    can you give an example of what you want to do? This makes no sense to me.

    Can you comment your code describing what each statement is supposed to do?
    For example, what is the following to do:

    intRates[counter]/12;
    Last edited by Norm; 05-24-2011 at 02:57 AM.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by bamagirl31 View Post
    Hi. I have an application set up with two variables such as x = term * 12; and y = rate /12; How can I set up term and rate with different amounts using an array if they are already initialized at 0? Can I set that up a different way? Thanks. I hope that better explains what I am attempting to do.
    This information is helpful because I find that often the best answer is not the one the original poster asks for, and that's the case here. I think of an array as a container to hold very similar entities such as a bunch of grades, or the heights of students in a class. Your problem on the other hand requires that you store two entities that have different meaning, one representing the length of a loan and the other the interest rate, and here you do not want to use an array but rather a new class, one with a term field and a rate field. Then you can create objects of this class and have them each hold a term value and a rate value, and can even create an array of these objects if desired.

    As for your code above, you're going to want to edit it and add [code][/code] tags (the first tag above your code block and the second below) so that the pasted code will retain its formatting and be readable.

  7. #7
    bamagirl31 is offline Member
    Join Date
    May 2011
    Posts
    47
    Rep Power
    0

    Default Posted code with Code tags

    Quote Originally Posted by Norm View Post
    PLEASE add code tags to your code to preserver formatting. It is hard to see where matching { and } are. Some of your code appears to be outside of any method.


    Can you explain? If the output is incorrect, please show what the current output is and explain the problem with it and show what it should be.


    can you give an example of what you want to do? This makes no sense to me.

    Can you comment your code describing what each statement is supposed to do?






    For example, what is the following to do:

    intRates[counter]/12;



    Java Code:
    package surveys;
    
    /**
     *
     * @author Lekeisha
     */
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    
    
    public class Surveys
    {
         public Surveys()
                 {
                 }   
        public static void main(String[] args)
            {        
            Surveys surveys1 = new Surveys();
            surveys1.inputFromConsole();
            }
        
        public void inputFromConsole()
                {
                    int answer1;
                    int answer2;
                    int tryAgain;
                    
                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         
                    
                 
                System.out.println("How many kids do you have?" );
                
                
                
                try
                {    
                    answer1 = br.read();
                }
                catch
                (IOException e)
                {
                    return;
                }    
                    System.out.println("How many pets do you have?");
                
                try
                {    
                    answer2 = br.read();
                }
                catch
                (IOException e)
                {       
                    return;
                }    
                
                System.out.println("Do you want to enter another set of answers? Enter 01 for Yes or 02 for No");
                
        
                try
                {    
                    tryAgain = br.read();
                }
                catch
                (IOException e)        
                {   
                    return;
                }    
                
        
             
        
                }
            // TODO code application logic here
          
                
            }
            
           
            // TODO code application logic here

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,459
    Rep Power
    25

    Default

    What is the purpose of your last post? You should start a new thread with a new problem.

Similar Threads

  1. store array of arrays in array of arrays
    By joost_m in forum New To Java
    Replies: 4
    Last Post: 04-19-2010, 10:32 AM
  2. Arrays.sort... why sorting all arrays in class?
    By innspiron in forum New To Java
    Replies: 6
    Last Post: 03-23-2010, 01:40 AM
  3. Arrays
    By swim_fan08 in forum New To Java
    Replies: 7
    Last Post: 04-11-2009, 03:02 PM
  4. Need help regarding Arrays Help pls....
    By shaggyoo7 in forum New To Java
    Replies: 3
    Last Post: 01-14-2009, 04:36 AM
  5. A little help with arrays..
    By zeppelin in forum New To Java
    Replies: 8
    Last Post: 01-05-2009, 12:33 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
  •