Help me making java program by Jcreator

1. reversing an integer problem:
a. write a program that allows a user to enter an integer up to 4 digits in length. The program should then reverse the order of the integer. The new number should have it's full decimal value (e.g. 432 is really 3*100 + 2*10+ 1*1)
Enter number:123
The reversal is 321
Enter number:1005
The reversal is 5001

OK the specification said smth. about decimal extension, here it is:
EXPLANATION:
I am just a 'medium-advanced' Java programer and do this because I wan't to
write more code and gather experience.
And if I just write code but don't show it to any body it would get wasted...
OK , ok now on I Stop helping Trolls and laymen.
* @author melhiah
public class ReverseAnInteger {
    private static final int MAX_INT_LEN = 6;
    public static void main(String[] args) throws Exception {
/*        if(args.length < 1) {
            System.out.println("Usage: java ReverseAnInteger <integer-value>");
            System.exit(0);
        //String parsedIntegerString = args[0].substring(0, MAX_INT_LEN);
        String testIntegerString = "1234567890";
        String parsedIntegerString;
        if(testIntegerString.length() < MAX_INT_LEN) {
            parsedIntegerString = testIntegerString.substring(0,
                    testIntegerString.length());
        } else {
            parsedIntegerString = testIntegerString.substring(0, MAX_INT_LEN);
        String reversedIntegerString = showDecimalExtension(
                reverseInt(parsedIntegerString));
        System.out.println(reversedIntegerString);
    private static String reverseInt(String intString) {
        char[] charString = intString.toCharArray();
        char[] resultString = new char[charString.length];
        int top = charString.length;
        for(int i = 0; i < charString.length; i++) {
            resultString[i] = charString[--top];
        return new String(resultString);
    private static String showDecimalExtension(String intString) {
        StringBuffer buffer = new StringBuffer();
        StringBuffer sb = new StringBuffer(); sb.append("1");
        for(int i = 1; i < intString.length(); i++) {
            sb.append("0");
        String decim = sb.toString();
        for(int i = 0; i < intString.length(); i++) {
            String str = intString.charAt(i) + "*" + decim + " + ";
            decim = decim.substring(0, decim.length() -1);
            buffer.append(str);
        String result = buffer.substring(0, buffer.length() -3); // to get rid of the trailing '+'
        return result;
}

Similar Messages

  • What is the  best money making java program?

    what is the best money making java program?
    any of them are in fact very "simple"? - say in fact can be develop by a middle- level programmer.

    public class MoneyMaker {
       public static void main(String[] args) {
          while (true) {
             System.out.println("+-----------------------------------------------+");
             System.out.println("| 10        RESERVE BANK OF INDIA \"93T 872468\"  |");
             System.out.println("|                                               |");
             System.out.println("|   ______                                   10 |");
             System.out.println("|  /      \\             __          ____        |");
             System.out.println("|  |      |        /|  /  \\        /  __\\       |");
             System.out.println("|  |      |         | |    |       0_o  \\\\      |");
             System.out.println("|  |      |         | |    |      /      ||     |");
             System.out.println("|  |      |         |  \\  /       `==    ||     |");
             System.out.println("|  |      |        ===  **         \\    /       |");
             System.out.println("|  |      |                        /\\--/        |");
             System.out.println("|  \\______/                       /______   /\\  |");
             System.out.println("|                                           \\/  |");
             System.out.println("| \"93T 872468\"                                  |");
             System.out.println("+-----------------------------------------------+");
             System.out.println("");
    }

  • Need Help with a JAVA programming assignment

    How do I write a JAVA program that could be used as the start of an MS-DOS/Windows simulation of the IEEE 802.3 protocol? I am to only code the parts necessary to build the 802.3 frame. For the initial implementation, the Checksum function need not be a CRC function, and the Destination and Source addresses wil be in input, stored, and output, and in dotted-decimal format.
    I need:
    1. A record to describe the frame, with each field being a (byte-) string of the required size, except that the Data field is of variable size. Although the "Source address" and "Destination address" would be 6 bytes for a real implementation, for this first implementation you can either assume they'll be text strings in the usual "dotted decimal" form (e.g. "14.04.05.18.01.25" as a typical example--from Tanenbaum, p. 429), or 6 hex digits.
    2. Suitable constant declarations for values such as the standard "Preamble" and "Start of Frame" values.
    3. Suitable functions to Get the three variable values "Destination address", "Source address", and "Data" from the standard input device.
    4. A suitable function to display each of the fields of a given frame in a format such as:
    Preamble: ...
    StartofFrame: ...
    Destination: ...
    etc.
    5. A suitable function to generate a "Pad" field if necessary.
    6. A "dummy" Checksum-generating function which just takes the first 32 bits (4 bytes) of the Data (or Data+Pad, if necessary) rather than an actual CRC algorithm.
    I have no experience with Java. Can you help me or start me in the right direction?
    Thanks...........TK

    If you have no experience with Java, then it seems to me your first step should be to start learning the language. But it's difficult to advise how, since we don't know anything about your background. There are many good books available on Java, some are for beginners and some are for advanced programmers, so I'd suggest you go somewhere that has a large selection and start looking for something that doesn't seem completely over your head.

  • Need Help with a Java program

    Hey
    I am doing a bachelor of Multimedia and for some reason I was forced to do Programming 1 which is just Java programing.I have been doing pretty well but we have the final exam coming up on Thursday and they told us to learn how to do this question but I have no idea how to do it, could someone please help me?
    Write a program that reads a file containing a list of students' student numbers and names, and then writes out another file in which the students have been formed into project groups.
    Sample input file:
    96439530 Naranek, Kosh
    08532109 Ivanova, Susan
    87642078 Sheridan, John
    44327889 Varner, Dell
    98100023 Kotto, Vir
    66345689 Sinclair, Jeffrey
    77421009 Garibaldi, Michael
    88775544 Winters, Talia
    54321098 Alexander, Lyta
    12345098 Mollari, Londo
    03465499 Takashima, Laurel
    88765432 Kyle, Benjamin
    08876500 Keffer, Warren
    07687878 Cole, Marcus
    For the project course: no group should have more than 5 members; and it is desireable that all groups have as close to 5 members as possible; and that students be allocated to groups alphabetically by family name, as in this sample output file:
    Group 1:
    Lyta Alexander (54321098)
    Susan Ivanova (08532109)
    Benjamin Kyle (88765432)
    John Sheridan (87642078)
    Dell Varner (44327889)
    Group 2:
    Marcus Cole (07687878)
    Warren Keffer (08876500)
    Londo Mollari (12345098)
    Jeffrey Sinclair (66345689)
    Talia Winters (88775544)
    Group 3:
    Michael Garibaldi (77421009)
    Vir Kotto (98100023)
    Kosh Naranek (96439530)
    Laurel Takashima (03465499)
    Students' names are first sorted (Alexander, Cole, Garibaldi, Ivanova, ...), then allocated to the tutes in rotation (Alexander to 1, Cole to 2, Garibaldi to 3, Ivanova to 1, ...).
    Note also that the student's details are written in a different format from the input. You may make the (usually wrong!) assumption that each student has a simple one-word family name and one other name.

    I'm sorry too annoy you again but I don't know how to implement what you told me. Here is my current code:
    import java.io.*;
    import java.util.*;
    class DetailSortTest {
         public void run() {
              try {
                   BufferedReader in = new
                   BufferedReader(new FileReader ("Data.txt"));
                   String line = in.readLine();
                   String[] names = new String [10];
                   int i = 0;
                   PrintWriter FileOut = new
                   PrintWriter(new FileWriter ("Data 2.txt"));
                   processFilesTest(in, FileOut);
                   in.close();
                   FileOut.close();
              } catch (FileNotFoundException f) {
                   System.out.println("Could Not Open The File");
              } catch (IOException i){
                   System.out.println(i.getMessage());
         public void processFilesTest (BufferedReader in, PrintWriter FileOut)
         throws IOException {
              String data[] = new String[100];
              List dList = new ArrayList();
              String NLine = in.readLine();
              FileOut.println(NLine);
         public static void main(String[] args) {
              DetailSortTest anObject = new
              DetailSortTest();
              anObject.run();
    How would I do it I tried:
    NLine.split(data[2]+""+data[1]+""+data[0]);
    But all that displays is null, null, null
    I know I am probably so stupid but I really appreciate the help

  • I need help in making the programe which updates our code into client machi

    I need help in making the programme which updates our code into client machine from the server.
    As yahoo messanger does if there is any updated version of yahoo messanger.
    It asks when we login into it do you want to update new version of yahoo messanger
    It automatically updates it
    Need Help??

    Sounds to me like you need Java Web Start.

  • Makeing java programming friends

    hi,thanks for focus on this.
    i am a chinese guy,working for a federal software company,having about half and one years java programming studying and working experience,which are mainly about jsp and j2ee programming. i am not very good at english ,but i am working on it. so i wanna more communication .and i think,maybe ,to java beginner, my experiense can make some help,Surely,i am a beginner.so hope to meet many friends.
    my msn is: [email protected]
    my freqently used email is: [email protected]
    Best Regards.
    Ryan Zhang

    Then go over to the JSP forum and try answering some
    questions. Even if you do not feel that your English
    is good enough, still see if you can find an answer.
    You do not have to actually post the answer. But if
    you are confident in your answer, go ahead and post
    it. Nobody will complain about your English skills.
    Only if the answer is wrong, will people complain.That's a very good advice. I'm answering questions because I want to become better in English, and I have learnt many new words since I started answering, but I have to admit that most of the new words and expressions comes from the off topic threads, and from Annies posts :)
    /Kaj

  • Help with a java program

    Hello. I'm posting in these forums because I really don't know where else to go. I have been trying for the past several days to figure out how to go about writing my program but to no avail. The project requires reading many lines each containing several different elements from a datafile named "DATA". A few examples of some lines from that file:
    Department number/Number of units received/Date on which the shipment arrived/Expiration date/Name of Object
    0 78 02/03/2001 02/12/2001 apples
    0 26 06/03/2001 06/10/2001 lemons
    3 62 03/06/2001 03/14/2001 hamburger
    What we have to do with this data is read all of it from the file, separate all the different elements, and based on input from the user, sort everything and print it out to the screen. If the user enters 03, the program will show everything that arrived and expired within the month of March, sorted by date.
    It is a pretty basic program, but my problem is that I have no idea how to go about reading in this data, putting it into a vector (probably the easiest method) or separating the different elements. I've gone to websites and looked through my textbooks but they didn't help much. If anyone has any resources that could help for writing such a program, or if anyone could offer help in writing the program, I would really appreciate it. I can also show what I've managed to write so far, or more details on how the program should work. Thanks in advance.
    Matt

    since im not a pro like some of the guys on here :),
    and believe me thiers people here, who could write your whole app in a hour.
    anyways my advice , would be to do a search on the forums for useing.bufferReader()
    i think you would need to read the file in with bufferreader then split up each line useing the stringTokenizer and then use some algorithm to compare
    the values and split them up into your vector arrays as needed.
    thier is also fileinputStream i think you can use that too.

  • HELP for Compile java programe !

    Hello All,
    i want to make java programe by which i can compile java programes
    and when i compile java programe from my programe then
    i shoul get compiled status means programe compile successfuly
    or not compile.
    if any example i m thanksfull.
    onlyforjava.

    how about if compile fail?
    the process obj seems return value 0 as it run successful.
    I haven't try this, but I have experienced the process obj returns 0 if the executed command has some routine to handle error cases, in which, error will not halt the system.
    So, I recommand the following scenario.
    1. let say, if your java is test.java. check the existence of file test.class.
    If, it exists, get its modified time.
    2. compile the java code with
    Procress p = Runtime.exec(new String[]{"javac", "test.java"});
    3. get the error string if any.
    InputStream in = new BufferedInputStream(p.getInputStream());int read;while ((read = in.read()) != -1){  System.out.println((char)read);}
    4. handle error with the exitValue
    if (p.exitValue() != 0){  System.out.println("warning.");}
    5. check again the file test.class if it is a newly created file.
    6. if it is newly created, compile success. Else, failed.

  • Help with Simple JAVA program

    I'm a complete novice with Java. I want to write a Java program to run on Windows 2000 servers to write a list of certain files in a directory into a *.txt file. I hope to add complexity once I have this basic part working. Here's the code I have so far:
    //this Java application finds poll* files
    public class FindPollApp
    //Create File Object
    File dir = new File("d:/jda/windss/poll");
    //List directory
    if(dir.isDirectory())
    String[] dirContents = dir.list();
    for (int i=0; i < dirContents.length; i++)
    System.out.println(dirContents);
    //Iterate through files
    I get the following errors:
    C:\JAVA>javac FindPollApp.java
    FindPollApp.java:9: illegal start of type
    if(dir.isDirectory())
    ^
    FindPollApp.java:18: <identifier> expected
    ^
    2 errors
    Thanks.

    I'm a complete novice with Java. I want to write a
    Java program to run on Windows 2000 servers to write
    a list of certain files in a directory into a *.txt
    file. I hope to add complexity once I have this
    basic part working. Here's the code I have so far:
    //this Java application finds poll* files
    public class FindPollApp
    //Create File Object
    File dir = new File("d:/jda/windss/poll");
    //List directory
    if(dir.isDirectory())
    String[] dirContents = dir.list();
    for (int i=0; i < dirContents.length; i++)
    System.out.println(dirContents);
    //Iterate through files
    I get the following errors:
    C:\JAVA>javac FindPollApp.java
    FindPollApp.java:9: illegal start of type
    if(dir.isDirectory())
    ^
    FindPollApp.java:18: <identifier> expected
    ^
    2 errors
    Thanks.
    You need to create a method and insert your if statement in there

  • I Need Help With Making This Program Work

    The directions for this program:
    Enhance the Student class to contain an Advisor. The advisor has a name (type Name), phone number (type String). Place edits in the Name class to validate that the length of the first name is between 1 and 15, middle inital <= 1, and lastName is between 1 and 15. Throw an IllegalArgumentException if the edits are not met. The advisor attribute in the Student class should replace the advisorName. Document the Name, Advisor, and Student classes including the preconditions and postconditions where necessary. Create a test class that will instantiate a Student, fully populate all of its fields and print it out. Do not document the test class. Submit for grade Student.java, Advisor.java, and Name.java.
    public class Student
         private Advisor advisorName;
         private Advisor phoneNumber;
         public void setAdvisorName(Advisor anAdvisorName)
             advisorName = anAdvisorName;
         public Advisor getAdvisorName()
             return advisorName;
         public void setPhoneNumber(Advisor aPhoneNumber)
             phoneNumber = aPhoneNumber;
         public Advisor getPhoneNumber()
             return phoneNumber;
    public class Name
         private String firstName;
         private String midInit;
         private String lastName;
         public String getFullName()
             return firstName + " " + midInit + " " + lastName;
         public String getFirstName()
             return firstName;
         public String getMidInit()
             return midInit;
         public String getLastName()
             return lastName;
            Calculates length of the first name.
            (Postcondition: getFirstName() >= 0)
            @param s the length of the first name to calculate
            (Precondition: length of aFirstName > 0 and <= 15)
         public void setFirstName(String aFirstName)
             if(aFirstName.length() < 1)
               throw new IllegalArgumentException();
             if(aFirstName.length() > 15)
               throw new IllegalArgumentException();
               firstName = aFirstName;
            Calculates length of the middle initial.
            (Postcondition: getMidInit() >= 0)
            @param s the length of the middle initial to calculate
            (Precondition: length of s > 0 and <= 1)
         public void setMidInit(String aMidInit)
             if(aMidInit.length() == 1)
               throw new IllegalArgumentException();
               midInit = aMidInit;
            Calculates length of the last name.
            (Postcondition: getLastName() >= 0)
            @param s the length of the last name to calculate
            (Precondition: length of aLastName > 0 and <= 15)
         public void setLastName(String aLastName)
             if(aLastName.length() < 1)
               throw new IllegalArgumentException();
             if(aLastName.length() > 15)
               throw new IllegalArgumentException();    
               lastName = aLastName;
    public class Advisor
         private Name advisorName;
         private String phoneNumber;
         public String getFullName()
            return advisorName + " " + phoneNumber + " ";
         public Name getAdvisorName()
             return advisorName;
         public String getPhoneNumber()
             return phoneNumber;
         public void setAdvisorName(Name anAdvisorName)
             advisorName = anAdvisorName;
         public void setPhoneNumber(String aPhoneNumber)
             phoneNumber = aPhoneNumber;
    public class Test
         public static void main(String[] args)
            Name name1 = new Name();
            name1.setFirstName("Timothy");
            name1.setLastName("O'Neal");
            name1.setMidInit("J.");
            System.out.println("name1 = " +
                name1.getFirstName() + " " +
                name1.getMidInit() + " " +
                name1.getLastName());
            Student st = new Student();
            st.setAdvisorName(name1);
            Name name2 = st.getAdvisorName();
            System.out.println("name2 = " +
                name2.getFirstName() + " " +
                name2.getMidInit() + " " +
                name2.getLastName());   
            name2.setFirstName("Timothy");
            System.out.println("name2 = " +
                name2.getFirstName() + " " +
                name2.getMidInit() + " " +
                name2.getLastName());       
            System.out.println("name1 = " +
                name1.getFirstName() + " " +
                name1.getMidInit() + " " +
                name1.getLastName());
            System.out.println("name1 = " + name1.getFullName());   
            System.out.println("name2 = " + name2.getFullName());
    }I can't get the test class to compile and i'm not sure if this is what i'm suppose to do

    public class Test
    public static void main(String[] args)
    Student st = new Student();
    Advisor advisor = new Advisor();
    st.setAdvisor(advisor);
    Name name1 = new Name();
    name1.setFirstName("Jake");
    name1.setLastName("Schmidt");
    name1.setMidInit("K.");You have the general idea, I think. You are just doing it backwards.
    You create and advisor and assign it to a student. But you don't give
    the advisor a name until after you assign it to the student.
    You should create an advisor, give the advisor a name and then add it to the student.
    //create the name
    Name name1 = new Name();
    name1.setFirstName("John");
    name1.setLastName("Smith");
    name1.setMidInit("K.");
    //create the advisor
    Advisor advisor = new Advisor();
    advisor.setAdvisorName(name1);
    //create the student
    Student student = new Student();
    //assign the advisor to the student
    student.setAdvisor(advisor);
    //now the student has an advisor named John K. Smith
    //What is the name of the advisor?
    String name = st.advisor.getAdvisorName().getFullName();
    //I know that line looks complicated...but that's how you have created your class structure.
    Instead you could have done:
    Class Student{
    private Advisor advisor;
    public String getAdvisorName(){
    return advisor.getFullName();
    class Advisor{
    private Name advisorName;
    public getFullName(){
    return advisorName.getFullName();
    This way, if you wanted to know the advisor's name you would go:
    String name = st.getAdvisorName();
    which is much easier.
    I think it would be much easier to help you if we were both in the same room, on the same computer :)

  • Help please with java programming

    ok so i need a little help on getting started on this program.
    i need to make a program where the user can enter the last names of candidates and the votes recieved by each candidate. then the program should output both the candidates names and the total votes recieved by each candidate and the perctage of votes each recieved.
    can anyone help me get started with some sample code. thanks.

    ok so this is what i have so far . . . . it goes through the array and works.
    im suppose to also have these two methods . . .
    sumVotes- Which will receive the votes array by reference.
    Calculate the total votes.- Return the calculated integral total votes.winnerIndex- Which will receive the votes array by reference.- Identify the top candidate who received more votes. - Return the identified index.
    my program is suppose to do this . . .The program should then output each candidate?s name, votes received by that candidate, and the percentage of the total votes received by the candidate. The program should also output the winner of the election.
    ok so anyone out there nice enough to tutor me through making these 2 methods i need?
    here is code of what i have so far
    package assign11942;
    import javax.swing.*;
    public class Assign11942 {
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              String strLast[],strNumCand, strVotes[];
              int numCand;
              double votes[], percentage, totalVotes[];
              strNumCand = JOptionPane.showInputDialog("Enter Number of Candidates: ");
              numCand = Integer.parseInt(strNumCand);
              strLast=new String[numCand];
              strVotes=new String[numCand];
              votes=new double[numCand];
              totalVotes=new double[numCand];
              for (int i =0 ; i < numCand; i++)  {
                   strLast= JOptionPane.showInputDialog("Enter Candidates Last Name: ");
                   strVotes[i]=JOptionPane.showInputDialog("Enter Number of Votes: ");

  • Need help with basic Java programming

    I'm having a little bit of trouble with my code. For the sake of argument, I've removed the code I'm having trouble with, because I know it was inaccurate. I'm trying to create a loop so that this program will keep going through and through until the user enters an invalid variable. I thought the default after the case statements was supposed to make the system exit and output my message. Those two problems, the loop and the default, are what I'm really having problems with. My code is posted below.
    import javax.swing.JOptionPane;
    import java.util.Locale;
    import java.text.NumberFormat;
    public class Retail
    public static void main(String args[])
    String firstNum;
    String secondNum;
    String result;
    int prodNum;      //first number to input
    double quantity; //second number to input
    double total = 0.0;     //total of Prod * Quantity Sold for all items
    // To use American Dollar
    NumberFormat moneyFormat = NumberFormat.getCurrencyInstance( Locale.US );
    // first number entered as string
    firstNum = JOptionPane.showInputDialog( "Enter product number 1-5" );
    // second number entered as string
    secondNum = JOptionPane.showInputDialog( " Enter quantity of items sold" );
    // convert values to type double or int from type string
    prodNum = Integer.parseInt( firstNum );
    quantity = Double.parseDouble( secondNum);
    result="";
    if ( prodNum >=1 && prodNum <=5 ) {
    switch (prodNum)
    case 1: // 1st product
    total = 2.98 * quantity;
    break;
    case 2: // 2nd product
    total = 4.50 * quantity;
    break;
    case 3: // 3rd product
    total = 9.98 * quantity;
    break;
    case 4: //4th product
    total = 4.49 * quantity;
    break;
    case 5:
    total = 6.87 * quantity;
    break;
    default: JOptionPane.showMessageDialog( null, "Wrong product number entered" );
    JOptionPane.showMessageDialog( null, moneyFormat.format(total), "Total Price of Items Purchased", JOptionPane.INFORMATION_MESSAGE );
    System.exit(0);
    ***I know I need to put something in the user input message to state that any value other than 1-5 entered will cause the program to skip to the output, I'll put that in later.***

    When you post code, please use [code] and [/code] tags as described in Formatting Help on the message entry page. It makes it much easier to read and prevents accidental markup from array indices like [i].

  • Need Help with a Java programming exercise.

    I have to Write a program that reads two times in military format (0900, 1730) and prints the number of hours and minutes between two times. Supply your own test program. Here are two sample runs. User inputs are the numbers.
    Please enter the first time: 0900
    Please enter the second time: 1730
    8 hours 30 minutes
    Please enter the first time: 1730
    Please enter the second time: 0900
    15 hours 30 minutes
    Test Program I can write up myself. But the entire constructor I have no idea how to start. This is basic Java Coding. no C++ no importing anything.
    So far this is what I got and I'm sure it's wrong:
    public class TimeInterval
    private double hours;
    private double minutes;
    public TimeInterval(double Time1, double Time2)
    hours =
    minutes =
    }

    tad2382 wrote:
    Jverd,
    I'm guessing that in your early days on this forum you must have spent a lot of time explaining constructors, object creation, etc. Now, after some 40K posts to the forum, you figure newbies should just go and read the documentation. Is that what a lot of veteran posters feel?Perhaps the OP is not aware of the fact the Sun has a good deal of high quality study material published on their website. What's wrong with posting it in a thread? Why should one copy the same thing over and over again? If after reading that tutorial, the OP still has some questions about it, s/he is free to post a follow up question. I am sure that many of the regulars here are more than happy to answer them.
    Also note that the OP's problem description is rather vague. A "I don't know where to start" is IMO best answered by a link to a comprehensive tutorial or a beginners book.
    Being one of the (relatively) novice posters on the forum, I still feel the need to customize posts,Well, by all means: do so.
    trying to see things from the poster's side. Maybe after a few thousand posts, I'll just keep throwing the same documentation at newbies, instead of detailed customized responses, heh.IMO, that's a load of cr@p.

  • Help!  Simple Java Program.

    Here is the problem: Write a program that creates a loan amortization table. The user of the program will supply values for Initial Loan Principal, Annual Percentage Rate and Monthly Payment. The program should print out the appropriate amortization table including the number of Monthly Payments and the Total Interest paid for the life of the loan. The program should allow multiple
    runs (up to 4 different versions) of the table process and should allow the
    user to compare runs in a tabular format.
    This is what I have so far and should work one I completely debug it. I am really new to Java, and I thinks it is somthing to do with the Array. I recently switched from C++ to Java, so I don't think I have the syntax down correctly. Thanks.
    import javax.swing.JOptionPane;
    public class Program_01
         public static void main(String [] args)
              int Runs;
              do{
                        String Run_Question = JOptionPane.showInputDialog(null, "How many times,would you like to run" + 
                        " the program? (Up to four runs only!)", "Run Question", JOptionPane.QUESTION_MESSAGE);
                         Runs = Integer.parseInt(Run_Question);
                        if( Runs < 0 || Runs > 4)
                             JOptionPane.showMessageDialog(null, "The number is not valid, try again!", "Error",
                             JOptionPane.INFORMATION_MESSAGE);
                   }while(Runs < 0 || Runs > 4);
                   Questions(Runs);
         public static void Questions(int Runs)
              for(int index = 0;index < Runs;index ++)
                   String Loan_Principle_String = JOptionPane.showInputDialog(null, "What is the Loan Principle?", "Loan Amount",
                                                         JOptionPane.QUESTION_MESSAGE);     
                   String Percentage_Rate_String = JOptionPane.showInputDialog(null, "What is the Annual Percentage Rate?",
                                                           "Interest Rate", JOptionPane.QUESTION_MESSAGE);
                   String Monthly_Payment_String = JOptionPane.showInputDialog(null, "What is the Monthly Payment", "Payment",
                                                           JOptionPane.QUESTION_MESSAGE);
                   double Loan_Principle = Double.parseDouble(Loan_Principle_String);
                   double Percentage_Rate = Double.parseDouble(Percentage_Rate_String);
                   double Monthly_Payment = Double.parseDouble(Monthly_Payment_String);
                   Calculate(Loan_Principle, Percentage_Rate, Monthly_Payment);
         public static void Calculate (double Loan, double Percentage, double Monthly)
              double[] Principle = new double[]{0,0};
              double[] Interest = new double[]{0,0};
              double[] Remain = new double[]{0,0};
              double Monthly_Percent = Percentage/12;
              double MPR = ((int)((Monthly_Percent + .005) * 100.) / 100.);
              boolean Over = true;          
              double Borrowed = Loan;          
              int Month = 0;
              for (int index = 0; Over != false; index++)
                   double Rate = MPR * Loan;
                   double decimalRate = ((int)((Rate + .005) * 100.) / 100.);
                   Interest[index] = decimalRate;
                   double Prince = Monthly - decimalRate;
                   double decimalPrince = ((int)((Prince + .005) * 100.) / 100.);
                   Principle[index]= decimalPrince;
                   double Rmn = Borrowed - decimalPrince;
                   Borrowed = Rmn;
                   double decimalRmn = ((int)((Rmn + .005) * 100.) / 100.);
                   Remain[index] = decimalRmn;
                   if(Monthly > Remain[index] && Remain[index] > 0)
                        Monthly = Remain[index];
                        Over = false;
                   Month += 1;
              System.out.println("I am here!" + Month);
              System.out.println("Payment #" + " " + "Principle" + " " + "Payment" + " " + "APR" + " " + "MPR" +
               " " + "Interest Payment" + " " + "Principle Payment");
              System.out.println("------------------------------------------------------------------------");
              for(int index = 0; index < Month; index++)
                   System.out.println((index + 1) + "\t" + Remain[index] + "\t" + Percentage + "\t" + MPR + "\t" + Interest[index]
                    + "\t" + Principle[index]);
    }

    Okay, here is my updated code. I am having trouble outputting my formate to align with each category.
    import javax.swing.JOptionPane;
    import java.text.DecimalFormat;
    public class Program_01
         public static void main(String [] args)
              int Runs;
              do
                   String Run_Question = JOptionPane.showInputDialog(null, "How many times would you like to run" + 
                   " the program? (Up to four runs only!)", "Run Question", JOptionPane.QUESTION_MESSAGE);
                    Runs = Integer.parseInt(Run_Question);
                   if( Runs < 0 || Runs > 4)
                        JOptionPane.showMessageDialog(null, "The number is not valid, try again!", "Error",
                        JOptionPane.INFORMATION_MESSAGE);
              }while(Runs < 0 || Runs > 4);
                   Questions(Runs);
         public static void Questions(int Runs)
              for(int index = 0;index < Runs;index ++)
                   String Loan_Principle_String = JOptionPane.showInputDialog(null, "What is the Loan Principle?", "Loan Amount",
                                                         JOptionPane.QUESTION_MESSAGE);     
                   String Percentage_Rate_String = JOptionPane.showInputDialog(null, "What is the Annual Percentage Rate?",
                                                           "Interest Rate", JOptionPane.QUESTION_MESSAGE);
                   String Monthly_Payment_String = JOptionPane.showInputDialog(null, "What is the Monthly Payment", "Payment",
                                                           JOptionPane.QUESTION_MESSAGE);
                   double Loan_Principle = Double.parseDouble(Loan_Principle_String);
                   double Percentage_Rate = Double.parseDouble(Percentage_Rate_String);
                   double Monthly_Payment = Double.parseDouble(Monthly_Payment_String);
                   Calculate(Loan_Principle, Percentage_Rate, Monthly_Payment);     
         public static void Calculate (double Loan, double Percentage, double Monthly)
              double[] Principle = new double[100];
              double[] Interest = new double[100];
              double[] Remain = new double[100];
              double[] Payment = new double[100];
              DecimalFormat Decimal = new DecimalFormat(".00");
              double Total_Interest = 0;
              double T_Interest;          
              double Monthly_Percent = (Percentage/12)/100;
              double MPR = Monthly_Percent;
              boolean Over = true;          
              double Borrowed = Loan;
              double Deposit = Monthly;          
              int Month = 0;
              for (int index = 0; Over = true; index++)
                   double Rate = MPR * Borrowed;
                   double decimalRate = round(Rate,2);
                   Interest[index] = decimalRate;
                   Remain[index] = Borrowed;
                   Month += 1;     
                   if(Monthly > Remain[index ] && Remain[index ] > 0)
                        for(int count = 0; count <= Month; count++)
                             Total_Interest += Interest[count];     
                        T_Interest = round(Total_Interest,2);
                        Payment[index] = T_Interest;
                        Deposit = T_Interest;     
                   else
                        Payment[index] = Deposit;     
                   double Prince = Deposit - decimalRate;
                   double decimalPrince = round(Prince,3);
                   Principle[index]= decimalPrince;
                   System.out.println("I am here!" + decimalPrince);
                   double Rmn = Borrowed - decimalPrince;
                   double decimalRmn = round(Rmn,2);
                   Borrowed = decimalRmn;
                   if(Monthly > Remain[index ] && Remain[index ] > 0)
                        Over = false;
                        break;
              System.out.println("Payment #" + " " + "Principle" + " " + "Payment" + " " + "Percentage" + " " + "MPR" +
               " " + "Interest Payment" + " " + "Principle Payment");
              System.out.println("----------------------------------------------------------------------------");
              for(int index = 0; index < Month; index++)
                   System.out.println("   " + (index + 1) + "\t   " + Decimal.format(Remain[index]) + "   " +
                   Decimal.format(Payment[index]) + "   " + Decimal.format(Percentage) + "     " + MPR +
                   "\t" + Decimal.format(Interest[index]) + "\t\t" + Decimal.format(Principle[index]));     
              T_Interest = ((int)((Total_Interest + .005) * 100.) / 100.);
              System.out.println("\n\t\t\t" + "Total Interest Paid \t" + T_Interest + "\n");
              for(int index = 0; index < Month; index++)
                   System.out.printf("%f %f\n", Principle[index],Remain[index]);
         public static double round(double val, int places) {
         long factor = (long)Math.pow(10,places);
         // Shift the decimal the correct number of places
         // to the right.
         val = val * factor;
         // Round to the nearest integer.
         long tmp = Math.round(val);
         // Shift the decimal the correct number of places
         // back to the left.
         return (double)tmp / factor;
    }

  • Urgent Help: Basic Level Java Programming

    Hi,
    I am a student taking Java classes, and I need help for a few questions of our Christmas Homework. They are pretty basic stuff and not that hard to do, given that you have the required knowledge. It is really urgent and important, so I would really appreciate it if someone can help.
    I am putting here the hardest question in the homework as an example. As I have said, if you are easily able to do this question, please contact me.
    "Write a java application that prints the following diamond shape. You may use output statements that print a single asterisk (*), a single space or a single newline character. Maximize your use of repetition (with nested for statements) and minimize the number of output statements."
    I cannot draw the diamond here but it goes like this: First line 1 star, second line 3 stars, third line 5 stars, fourth line 7 stars, fifth line 9 stars, and it descends the same way (9 7 5 3 1) to complete the diamond.
    Thank you.

    Hi,
    I am a student taking Java classes, and I need help
    for a few questions of our Christmas Homework. They
    are pretty basic stuff and not that hard to do, given
    that you have the required knowledge. It is really
    urgent and important, Not to anyone else but you. We're volunteers, as you should know.
    so I would really appreciate it
    if someone can help.Isn't that cheating?
    Better that you take a shot at it and let people advise you on how to correct problems.
    I am putting here the hardest question in the
    homework as an example. As I have said, if you are
    easily able to do this question, please contact me.Yes, it's easy to do. Hints: Think System.out.println for the stars and two for loops.
    "Write a java application that prints the following
    diamond shape. You may use output statements that
    print a single asterisk (*), a single space or a
    single newline character. Maximize your use of
    repetition (with nested for statements) and minimize
    the number of output statements."
    I cannot draw the diamond here but it goes like this:
    First line 1 star, second line 3 stars, third line 5
    stars, fourth line 7 stars, fifth line 9 stars, and
    it descends the same way (9 7 5 3 1) to complete the
    diamond.
    Thank you.*
    Kinda like that...
    Think about the steps you'd follow to type this in yourself and then write them out in Java.
    %

Maybe you are looking for

  • Sync/Async BPM scenario : Problem at Integration Process..!!

    Hi All, I am doing Sync/Async BPM scenario. start ->Receive(Request)> Transformation(Responsemap)>Send(SendtoR/3)->Send(Send Response) ---> stop. When Iam trying to Activate, Integration process giving errors as Source parameter AA_Payment_Req | http

  • Export the Code of forms !!

    hallo !! i wanna ask about ... how we can Export The Code of the forms ... because ,, i wanna get the code to put it in my Project documentation !! plz help me ! Shenouda Bertel

  • How to check inventory inconsistence btwn EWM Vs ECC

    Hi Experts, Is there any report to check inventory inconsistence btwen EWM Vs ECC? Like WMS LX23 to clear difference btwn IM Vs WM stock? Thanks, Julia

  • Using a file as a table

    Hi, I know that it is possible to use a file (text file) as a table in 9i I don't however know how to do it. Does anyone know how to do this? Thanks, Ed.

  • BPEL PM looking for correlation id

    Hi. I have BPEL process with 2 receive activities and correlation set. In first initialize I set correlation id. For example: process is Ordering and correlaion id is Order number. Admin sometimes have to look at instance of order. Is there posibilit