I need an Array in my JAVA CODE

I need an array in my java code for my last class in my Java 1 course
my code does compile in dos using javac,....and it does work
It is a mortgage calculator for 3 loans of 3 different years loaned,.... and each have a different interest rate.
I need to have my code in an ARRAY for my last week .
any help would be appreciated
here is my code :
import java.text.*;           //20 May 2008, Revision ...many
import java.io.IOException;
class memortgage     //program class name
  public static void main(String[] args) throws IOException
    double amount,moPay,totalInt,principal = 200000; //monthly payment, total interest and principal
    double rate [ ] = {.0535, .055, .0575};          //the three interest rates
    int [ ] term = {7,15,30};                        //7, 15 and 30 year term loans
    int time,ratePlace = 0,i,pmt=1,firstIterate = 0,secondIterate = 0,totalMo=0;
    char answer,test;
    boolean validChoice;
    System.in.skip(System.in.available());           //clear the stream for the next entered character
    do
      validChoice = true;
      System.out.println("What Choice would you Like\n");
      System.out.println("1-Interest rate of 5.35% for 7 years?");       //just as it reads for each to select from
      System.out.println("2-Interest rate of 5.55% for 15 years?");
      System.out.println("3-Interest rate of 5.75% for 30 years?");
      System.out.println("4-Quit");
      answer = (char)System.in.read();
      if (answer == '1')  //7 yr loan at 5.35%
        ratePlace = 0;
        firstIterate = 4;
        secondIterate = 21;
        totalMo= 84;
      else if (answer == '2') //15 yr loan at 5.55%
        ratePlace = 1;
        firstIterate = 9;      //it helps If I have the correct numbers to calcualte as in 9*20 to equal 180...that why I was off -24333.76
        secondIterate = 20;    //now it is only of -0.40 cents....DAMN ME
        totalMo = 180;
      else if (answer == '3') //30 yr loan at 5.75%
        ratePlace = 2;
        firstIterate = 15;
        secondIterate = 24;
        totalMo = 360;
      else if (answer == '4') //exit or quit
        System.exit(0);
      else
        System.in.skip(System.in.available());               //validates choice
        System.out.println("Invalid choice, try again.\n\n");
        validChoice = false;
    }while(!validChoice);  //when a valid choice is found calculate the following, ! means not, similar to if(x != 4)
    for(int x = 0; x < 25; x++)System.out.println();
    amount = (principal + (principal * rate[ratePlace] * term[ratePlace] ));
    moPay = (amount / totalMo);
    totalInt = (principal * rate[ratePlace] * term[ratePlace]);
    DecimalFormat df = new DecimalFormat("0.00");
    System.out.println("The Interest on $" + (df.format(principal) + " at " + rate[ratePlace]*100 +
    "% for a term of "+term[ratePlace]+" years is \n" +"$"+ (df.format(totalInt) +" Dollars\n")));
    System.out.println("\nThe total amount of loan plus interest is $"+(df.format(amount)+" Dollars.\n"));
    System.out.println("\nThe Payments spread over "+term[ratePlace]* 12+" months would be $"+
    (df.format (moPay) + " Dollars a month\n\n"));
    System.in.skip(System.in.available());
    System.out.println("\nWould you like to see a planned payment schedule? y for Yes, or x to Exit");
    answer = (char)System.in.read();
    if (answer == 'y')
      System.out.println((term[ratePlace]*12) + " monthly payments:");
      String monthlyPayment = df.format(moPay);
      for (int a = 1; a <= firstIterate; a++)
        System.out.println(" Payment Schedule \n\n ");
        System.out.println("Month Payment Balance\n");
        for (int b = 1; b <= secondIterate; b++)
          amount -= Double.parseDouble(monthlyPayment);
          System.out.println(""+ pmt++ +"\t"+ monthlyPayment + "\t"+df.format(amount));
        System.in.skip(System.in.available());
        System.out.println(("This Page Is Complete Press [ENTER] to Continue"));
        System.in.read();
}

here is what was commented from my instructor for my week 4...is what you sen in the code....but I fixed loan 2 tonight
"Week 4 Great work, the numbers were a little off on the 1st and 2nd loans. Next time
try putting the values you displayed in an array. "
import java.text.*;           //20 May 2008, Revision ...many
import java.io.IOException;
class memortgage     //program class name
  public static void main(String[] args) throws IOException
    double amount,moPay,totalInt,principal = 200000; //monthly payment, total interest and principal
    double rate [ ] = {.0535, .055, .0575};          //the three interest rates
    int [ ] term = {7,15,30};                        //7, 15 and 30 year term loans
    int time,ratePlace = 0,i,pmt=1,firstIterate = 0,secondIterate = 0,totalMo=0;
    char answer,test;
    boolean validChoice;
    System.in.skip(System.in.available());           //clear the stream for the next entered character
    do
      validChoice = true;
      System.out.println("What Choice would you Like\n");
      System.out.println("1-Interest rate of 5.35% for 7 years?");       //just as it reads for each to select from
      System.out.println("2-Interest rate of 5.55% for 15 years?");
      System.out.println("3-Interest rate of 5.75% for 30 years?");
      System.out.println("4-Quit");
      answer = (char)System.in.read();
      if (answer == '1')  //7 yr loan at 5.35%
        ratePlace = 0;
        firstIterate = 4;
        secondIterate = 21;
        totalMo= 84;
      else if (answer == '2') //15 yr loan at 5.55%
        ratePlace = 1;
        firstIterate = 9;      //it helps If I have the correct numbers to calcualte as in 9*20 to equal 180...that why I was off -24333.76
        secondIterate = 20;    //now it is only of -0.40 cents....DAMN ME
        totalMo = 180;
      else if (answer == '3') //30 yr loan at 5.75%
        ratePlace = 2;
        firstIterate = 15;
        secondIterate = 24;
        totalMo = 360;
      else if (answer == '4') //exit or quit
        System.exit(0);
      else
        System.in.skip(System.in.available());               //validates choice
        System.out.println("Invalid choice, try again.\n\n");
        validChoice = false;
    }while(!validChoice);  //when a valid choice is found calculate the following, ! means not, similar to if(x != 4)
    for(int x = 0; x < 25; x++)System.out.println();
    amount = (principal + (principal * rate[ratePlace] * term[ratePlace] ));
    moPay = (amount / totalMo);
    totalInt = (principal * rate[ratePlace] * term[ratePlace]);
    DecimalFormat df = new DecimalFormat("0.00");
    System.out.println("The Interest on $" + (df.format(principal) + " at " + rate[ratePlace]*100 +
    "% for a term of "+term[ratePlace]+" years is \n" +"$"+ (df.format(totalInt) +" Dollars\n")));
    System.out.println("\nThe total amount of loan plus interest is $"+(df.format(amount)+" Dollars.\n"));
    System.out.println("\nThe Payments spread over "+term[ratePlace]* 12+" months would be $"+
    (df.format (moPay) + " Dollars a month\n\n"));
    System.in.skip(System.in.available());
    System.out.println("\nWould you like to see a planned payment schedule? y for Yes, or x to Exit");
    answer = (char)System.in.read();
    if (answer == 'y')
      System.out.println((term[ratePlace]*12) + " monthly payments:");
      String monthlyPayment = df.format(moPay);
      for (int a = 1; a <= firstIterate; a++)
        System.out.println(" Payment Schedule \n\n ");
        System.out.println("Month Payment Balance\n");
        for (int b = 1; b <= secondIterate; b++)
          amount -= Double.parseDouble(monthlyPayment);
          System.out.println(""+ pmt++ +"\t"+ monthlyPayment + "\t"+df.format(amount));
        System.in.skip(System.in.available());
        System.out.println(("This Page Is Complete Press [ENTER] to Continue"));
        System.in.read();
}

Similar Messages

  • Help Needed in AD Connection form Java Code

    Hi,
    I want to connect to AD target form my java program.
    We are doing this as we don't want to use the OOTB Connectors.
    How can any one connect to AD target from Java program?
    After connecting,
    How to Create a User in AD? Is there any API? Which one?
    Regards,
    SK

    You'll want to do a search on JNDI and Java code. There are lots of sample code available on the web and tutorials. Here's a list of the classes you'll probably be using:
    import javax.naming.CommunicationException;
    import javax.naming.Context;
    import javax.naming.NameNotFoundException;
    import javax.naming.NamingEnumeration;
    import javax.naming.NamingException;
    import javax.naming.OperationNotSupportedException;
    import javax.naming.directory.Attribute;
    import javax.naming.directory.Attributes;
    import javax.naming.directory.BasicAttribute;
    import javax.naming.directory.BasicAttributes;
    import javax.naming.directory.DirContext;
    import javax.naming.directory.InitialDirContext;
    import javax.naming.directory.ModificationItem;
    import javax.naming.directory.SearchControls;
    import javax.naming.directory.SearchResult;
    -Kevin

  • Need some urgent help with Java code...

    Hello
    i am taking a java class..beginner..and i am a dud at programming...
    had a couple of questions ..how do make a program ignore negative
    integer values,make it terminate when zero is entered instead of a number ,how should i calculate maximum minimum of integers..please help me..
    thanks
    damini

    You got some good advice from Java_Jay.
    Here is a snippet I keep handy for console input and output. It doesn't do your home work but gives you a working example of getting numbers from stdin:
    import java.io.*;
    public class DemoKeyboardInput {
         public static void main(String[] args) throws IOException {
              // open keyboard for input (call it 'stdin')
              BufferedReader stdin = new BufferedReader(new InputStreamReader(
                        System.in), 1);
              // get input from the keyboard
              System.out.print("Please enter your name: ");
              String name = stdin.readLine();
              System.out.print("Please enter your age: ");
              String s1 = stdin.readLine();
              System.out.print("Please enter the radius of a circle: ");
              String s2 = stdin.readLine();
              // perform conversions on input strings
              int age = Integer.parseInt(s1); // string to int
              double radius = Double.parseDouble(s2); // string to double
              // operate on data
              age++; // increment age
              double area = Math.PI * radius * radius; // compute circle area
              // output results
              System.out.println("Hello " + name);
              System.out.println("On your next birthday, you will be " + age
                        + " years old");
              System.out.println("Area of circle is " + area);
    }

  • How i can use ExportPDF in java code to get html files as PDF?

    I need to use ExportPDF in java code to export my html to PDF and save that in my local system.

    Yes, it's not a service for automating. Automating Acrobat is a possibility (though awkward), or there are server products.

  • Class compiling/executing JAVA-Code??

    Hi!
    Stupid question: ;-)
    Is there a possibility to "parse" Java-Code into a JAVA-Class or to give JAVA-Code to a class that compiles the code and execute it?
    Thanks for answering!
    Mark Hauchwitz.

    background: we're running servlets and simply need to "parse" specialized/customized java-code for every customer into the servlet code. Source: database or whatever...
    How to get started?

  • Need help in writing a small java code

    Hi,
    I have a small requirement where I need write a small java code. I am thinking of using array. Please suggest if you know the solution:
    1. Need to compare user logon id is preset in the lookup table or not.
    2. If user id present in the lookup then send type "A" mail
    3. If user id in not present in the lookup then send type "B" email.
    Please suggest.
    Thanks,
    Kalpana.

    use this code . you have to pass userlogin and lookup name
    Public String GetEmail(String UserLogin,String lookupcode)
    String email;
    try{
    tcLookupOperationIntf lookupIntf = Platform.getService(tcLookupOperationIntf.class);
    HashMap<String, String> lookupValues = getLookupHashMap(lookupIntf, lookupCode);
    String found = lookupValues.get(UserLogin);
    if (found!=null) email= "EMAIL A";
    else
    email= "EMAIL B";
    }catch(Exception e){}
    return email;
    private HashMap<String, String> getLookupHashMap(tcLookupOperationsIntf lookupOperationsIntf, String lookupCode)throws tcAPIException,tcInvalidLookupException,tcColumnNotFoundException {
    HashMap<String, String> lookupMap = new HashMap<String, String>();
              tcResultSet resultLookupHashMap = lookupOperationsIntf
                        .getLookupValues(lookupCode);
              int countResultLookupHashMap = resultLookupHashMap.getRowCount();
    if (countResultLookupHashMap > 0) {
                   for (int i = 0; i < countResultLookupHashMap; i++) {
                        resultLookupHashMap.goToRow(i);
                        lookupMap.put(resultLookupHashMap..getStringValue("Lookup Definition.Lookup Code Information.Code Key"),
    resultLookupHashMap.getStringValue("Lookup Definition.Lookup Code Information.Decode"));
    return lookupMap;
    }

  • I Need Java code for following Algorithm

    * I Need Java code for following algorithm. Kindly any one help.
    1. Read the contents (ideas and its corresponding scores) from two files named as 'a' and 'b'.
    2. Stored the file 'a' contents in array a[].
    3. Stored the file 'b' contents in array b[].
    4. compare both files like
    if(a.equals(b[j])
    Writing the common idea and add the score from file 'a' and 'b'.
    else
    write the uncommon idea and its score..
    For example :
    Form Agents.txt
    action,65
    architecture,85
    eco-,15
    essay,30
    form,85
    form,85
    link,40
    tangent,25
    Form Agents1.txt
    Black holes,69
    essay,78
    Herewith i have above mentioned two files named as Form Agents and Form Agents1.
    Form Agents has eight fields
    Form Agents1 has two fields
    --> 'essay' is common in two files, so store the idea 'essay' and add the score from Form Agents score is '30' and Form Agents1 has 78 (essay 108).
    Finally it stores idea in another file with uncommon fields also.
    Please help us.

    We have tried with following code.
    But we cant add the scores.
    For Example:
    Form Agents.txt --> has "essay,30"
    Form Agents1.txt --> has "essay,78"
    Result is: essay,108
    Finally it stores idea in another file with uncommon fields also.
    So Any one pls correct the following code.
    try
    DataOutputStream o1=new DataOutputStream(new
    FileOutputStream("C:\\Interfaces\\interfaces\\temp\\BlackBoard\\My Design
    World\\Project\\Material\\art\\System Agents\\Form Agents\\CandidateResponses\\Form
    Agents.txt"));
    //Reading the contents of the files
    BufferedReader br= new BufferedReader(new InputStreamReader(new
    FileInputStream("C:\\Interfaces\\interfaces\\temp\\BlackBoard\\My Design
    World\\Project\\Material\\art\\System Agents\\Form Agents\\Ideological\\Form
    Agents.txt")));
    BufferedReader br1= new BufferedReader(new InputStreamReader(new
    FileInputStream("C:\\Interfaces\\interfaces\\temp\\BlackBoard\\My Design
    World\\Project\\Material\\art\\System Agents\\Form Agents\\Related\\Form
    Agents.txt")));
    while((s=br.readLine())!=null)
    s1+=s+"\n";
    while((s2=br1.readLine())!=null)
    s3+=s2+"\n";
    int numTokens = 0;
    StringTokenizer st = new StringTokenizer(s1);
    String[] a = new String[10000];
    String[] br_n=new String[10000];
    int i=0;
    while (st.hasMoreTokens())
    s2 = st.nextToken();
    a=s2.substring(0,s2.length()-3);
    s6=s2.substring(s2.length()-2);
    br_n[i]=s6;
    i++;
    numTokens++;
    int numTokens1 = 0;
    StringTokenizer st1 = new StringTokenizer (s3);
    String[] b = new String[10000];
    String[] br1_n=new String[1000];
    int j=0;
    while (st1.hasMoreTokens())
    s4 = st1.nextToken();
    b[j]=s4.substring(0,s4.length()-3);
    s7=s4.substring(s4.length()-2);
    br1_n[j]=s7;
    j++;
    numTokens1++;
    int x=0;
    for(int m=0;m<a.length;m++)
    for(int n=0;n<b.length;n++)
    if(a[m].equalsIgnoreCase(b[n])){
    int sc=Integer.parseInt(br_n[m]);
         int sc1=Integer.parseInt(br1_n[n]);
    int score=sc+sc1;
         o.writeBytes(a[m]+","+score+"\n");
    break;
    else
    o.writeBytes(a[m]+","+br_n[m]+"\n");
    break;
    }catch(Exception e){}

  • How to read XI Data type in Java code and populate as array list, using UDF

    Hi,
    How to read XI Data type in Java code and populate as array list, using UDF?
    Is there any API using which  the XI data types can be read?
    Kindly reply.
    Richa

    Input Structure:
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:CustomerCreateResp xmlns:ns0="urn:bp:xi:up:re:cust_mdm:cmdm:pr5:100">
       <CUSTOMER>
          <item>
             <CUSTOMERNO/>
             <MDMCUSTOMER/>
             <CREATE_DATE/>
             <RETURN>
                <TYPE/>
                <MESSAGE/>
             </RETURN>
             <PT_CONTPART_RETURN>
                <item>
                   <MDM_CONTACT/>
                   <CONTACT/>
                </item>
             </PT_CONTPART_RETURN>
             <PARTNERS>
                <item>
                   <CUSTOMERNO/>
                   <PARTNER_FUNCTION/>
                   <PARTNER_NUMBER/>
                   <DEFAULT_PARTNER/>
                </item>
             </PARTNERS>
          </item>
       </CUSTOMER>
    </ns0:CustomerCreateResp>
    Output structure
    (Sample output structure.This actually needs to be mapped and generated using UDF)
    <?xml version="1.0" encoding="UTF-8"?>
    <ns1:updateCustomer xmlns:ns1="urn:xiSericeVi"><ns1:customer><ns2:ArrayList xmlns:ns2="java:sap/standard">[]</ns2:ArrayList></ns1:customer><ns1:name>2344566</ns1:name></ns1:updateCustomer>

  • Need XSLT mapping or Java code?

    Hi All,
    I have a scenario JMS to Proxy.At sender side i will get complete XML payload in the single string.
    Root
      XMLpayload
    in XMLpaload i will get complete data in XML format.
    receiver side the structure is like this.
    Root
      Header       Header occurence is only once
         hr1
         hr2
         hr3
      Item           Item ocurence will be 0 ..U
         item1
         item2
    I need the code for XSLT mapping or for JAVA code that can be written in mapping.
    Regards,
    Phani

    Hi,
      could you please let me know, what is your source data type.
      by using node functions like split value , collapse context and foramt example.
    we can get th out put i the required format.
    pls let me know, your source and target data type.
    wamr regards
    mahesh.

  • Hi I need this asap... "Java code to generate XML File from XML Schema"

    Hi all....
    I need this asap... "Java code to generate XML File from XML Schema i.e XML Schema Definition, XSD file".
    Thankz in advance...
    PS: I already posted in the afternoon... this is the second posting.

    take look at :
    http://sourceforge.net/projects/jaxme/
    this might help...

  • Need to call webservice WSDL directly from Java code

    Hi All,
    I hope u all are doing great.
    I am new to web services and i have a requirement where i need to call the webservice directly from the java code, we dont need any middle layer(via proxy n all).
    Can you all please help me on this, we are using Jdeveloper 11g and we do have WSDLs
    we shld be able to use the wsdl in code and pass the request and get the request
    Any help will be appreciated
    Thanks

    @Puthanampatti     
    Thanks, but i already went through this link and seems this link also says we need to access webserivice through stub,dii etc.
    I want straught java code to access webservice without any tier in between
    Thanks

  • I need java code to flatten an image

    Hy! I need java code to flatten an image/sketch...someone can help me? Thanks to everybody!

    http://java.sun.com/developer/technicalArticles/Security/JCE/ ?

  • I need java code for chating application

    i need java code for chating application. plz help me

    GANGINENI wrote:
    i need java code for chating application. plz help meGIYF.
    [http://today.java.net/pub/a/today/2006/10/05/instant-messaging-for-jabber-with-smack.html|http://today.java.net/pub/a/today/2006/10/05/instant-messaging-for-jabber-with-smack.html]
    File under: lern2Google

  • Need Java Code or Program to compare 2 XML files ???

    Hi All,
    I need Any java code snippet to compare 2 XML files? Please help me..
    Thanks,
    J.Kathir

    Can you explain which possibilities you rejected while searching for that on the Internet? That may give us some insight into your actual requirements.

  • Need to track windows processes through java code.

    Need to track windows processes through java code.
    Eg: I want to find out whether an exe file (wrun.exe) is running or stopped.
    Can I do it through java. If so can any one please tell me how to do it. That will be a great help.
    Thanks,
    Ramesh

    There are 2 options for things like this:
    1) Use Runtime.exec() to execute some command or application and parse the input from it.
    2) Write some native code and use JNI to call it.

Maybe you are looking for

  • Help program not working.

    Dear All I using a Java Book called Java Gently written by J.Bishop Im working on a program and its typed out correctly and compiled corretcly, but for some reason wont work i dont know what parameters i need to enter. take a look: class CurioStore1

  • How can I view the iMessages that were sent to me while I was out of the country?

    How can I view the iMessages that were sent to me while I was out of the country? They never loaded, but people have told me that they sent me many iMessages while I was gone. I figured they would load when I turned on my cellular data, but only my t

  • Marketing attribute valid for a specific customer only?

    Hi We have a requirement that a specific marketing attribute set should only be valid for a specific group of customers. Is this possible to define in customizing? Any other suggestions of how to solve this? BR Johan

  • Freezing or Non-responsive

    It looks like problems others are encountering -- apps and camera shutter are locking up or display is non-responsive to touch. Usually first reboot does not fix freezing. I hope these will be addressed in iOS 7. Also, 5th generation is useless in br

  • The deal with the new subtitles and audio track feature...

    During the keynote, Jobs claimed that chapter selection, subtitles and alternate audio tracks for movies were a new feature on the iPhone. Why that feature would only be available on the iPhone is beyond me -- I assume that the feature is actually av