Help With Programming in Java (Using JEdit)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • djtosh
    Banned
    New Member
    • Mar 2007
    • 18

    Help With Programming in Java (Using JEdit)

    hi i dont know if this is the right place to be asking this but im trying to create a small program in java that can calculate the area of a square and then of multiple squares if the user enters the number of squares and the size increment of the squares,i.e.

    // Get Length(L)
    System.out.prin t("What is the length of the square: ?");
    L = data_input.next Double();

    // Get Number of square areas to calculate(N)
    System.out.prin t("How many squares do you want to calclate: ?");
    N = data_input.next Double();

    //Get Square size increment(I
    System.out.prin t("Please enter the square size increment: !");
    I = data_input.next Double()

    just hoping someone can help me to get the output correctly so that it shows the amount of square areas corresponding to N and that the L in each case increases by the amount corresponding with I, thanks in advance if anyone can help me, will be hugely appreciated. thanks
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    you have the basis of the program so why not create a simple test class, read in some data and then format the output until it meets your requirements?

    Comment

    • djtosh
      Banned
      New Member
      • Mar 2007
      • 18

      #3
      hi i dont know what those things are, my problem specificaly is how to make it so that the output calculates the amount of squares and by the size increment based on user input, thanks anyway.

      Comment

      • djtosh
        Banned
        New Member
        • Mar 2007
        • 18

        #4
        anybody got any ideas of how i would do this, i know i have to create an array but i dont know what to do after that.

        Comment

        • pronerd
          Recognized Expert Contributor
          • Nov 2006
          • 392

          #5
          Originally posted by horace1
          you have the basis of the program so why not create a simple test class, read in some data and then format the output until it meets your requirements?

          Originally posted by djtosh
          hi i dont know what those things are
          Well if you do not know how to even compile your code to make a class to run I am not sure any one here can help you.

          Comment

          • djtosh
            Banned
            New Member
            • Mar 2007
            • 18

            #6
            ok so i thought this was a place to get help for a problem with java, which is why i asked and gave speciific details, im not asking about how to compile im asking about my problem with the array,<Removed by moderator>

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by djtosh
              ok so i thought this was a place to get help for a problem with java, which is why i asked and gave speciific details, im not asking about how to compile im asking about my problem with the array,<Removed by moderator>
              Well no need for obscenities.

              Just create a class and put in a main method and the code you posted earlier and let's see how it looks.

              Comment

              • djtosh
                Banned
                New Member
                • Mar 2007
                • 18

                #8
                ok sorry about that but his post aggrevated as it was totally uneccessary and didnt help at all, i know you say just create a class with the main method, my problem is what the main method should be, obviously the equation for the area is (L*L) but how do i work the I and N into it to get what I want?

                Comment

                • r035198x
                  MVP
                  • Sep 2006
                  • 13225

                  #9
                  Originally posted by djtosh
                  ok sorry about that but his post aggrevated as it was totally uneccessary and didnt help at all, i know you say just create a class with the main method, my problem is what the main method should be, obviously the equation for the area is (L*L) but how do i work the I and N into it to get what I want?
                  Code:
                   
                  public class MyProgram {
                   public static void main(String[] args) {
                    //You program logic goes here
                   }
                  }
                  Now you just write your logic in the main method.

                  Comment

                  • djtosh
                    Banned
                    New Member
                    • Mar 2007
                    • 18

                    #10
                    ok i think the problem here is that im not using the proper terms to explain what i mean. i know how to create a class and how to create methods, i dont know how get it so that there are N(determined by user) amount of square areas in the ouput, and that the L in (L*L) is increased each time by I (determined by user ). Its the actual coding of this, that i dont know how to do.

                    Comment

                    • r035198x
                      MVP
                      • Sep 2006
                      • 13225

                      #11
                      Originally posted by djtosh
                      ok i think the problem here is that im not using the proper terms to explain what i mean. i know how to create a class and how to create methods, i dont know how get it so that there are N(determined by user) amount of square areas in the ouput, and that the L in (L*L) is increased each time by I (determined by user ). Its the actual coding of this, that i dont know how to do.
                      If you have one square of side size n then area is
                      Code:
                       double area = n * n;
                      If you have N squares then the total area is

                      Code:
                       double totalArea = N * n * n;

                      Comment

                      • djtosh
                        Banned
                        New Member
                        • Mar 2007
                        • 18

                        #12
                        L - the size of the side of the initial square
                        N - the amount of squares that need to be calculated
                        I - is the increment value that the L is increased by for each square

                        so if the user enters L=3, N=3, I=2

                        then the program should output

                        1st square area = 9 (3*3)
                        2nd square area = 25 (5*5)
                        3rd square area = 49 (7*7)

                        i suppose i shud of put this in the original post as to avoid the confusion

                        Comment

                        • r035198x
                          MVP
                          • Sep 2006
                          • 13225

                          #13
                          Originally posted by djtosh
                          L - the size of the side of the initial square
                          N - the amount of squares that need to be calculated
                          I - is the increment value that the L is increased by for each square

                          so if the user enters L=3, N=3, I=2

                          then the program should output

                          1st square area = 9 (3*3)
                          2nd square area = 25 (5*5)
                          3rd square area = 49 (7*7)

                          i suppose i shud of put this in the original post as to avoid the confusion

                          Code:
                           
                          double area = 0;
                            int L = 3;
                            int N = 3;
                            int I = 2;
                            for(int i = 0 ; i < N; i ++) {
                             area = area + (L * L);
                             L = L + I;
                            }
                            System.out.println(area);

                          Comment

                          • djtosh
                            Banned
                            New Member
                            • Mar 2007
                            • 18

                            #14
                            thanks mate ill try that out it looks similar to what i thought i had to do, thanks very much

                            Comment

                            • r035198x
                              MVP
                              • Sep 2006
                              • 13225

                              #15
                              Originally posted by djtosh
                              thanks mate ill try that out it looks similar to what i thought i had to do, thanks very much
                              Let us know how it goes.

                              Comment

                              Working...