473,326 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Help With Programming in Java (Using JEdit)

18
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.print("What is the length of the square: ?");
L = data_input.nextDouble();

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

//Get Square size increment(I
System.out.print("Please enter the square size increment: !");
I = data_input.nextDouble()

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
Mar 3 '07 #1
17 1893
horace1
1,510 Expert 1GB
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?
Mar 3 '07 #2
djtosh
18
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.
Mar 3 '07 #3
djtosh
18
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.
Mar 8 '07 #4
pronerd
392 Expert 256MB
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?

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.
Mar 8 '07 #5
djtosh
18
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>
Mar 9 '07 #6
r035198x
13,262 8TB
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.
Mar 9 '07 #7
djtosh
18
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?
Mar 9 '07 #8
r035198x
13,262 8TB
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?
Expand|Select|Wrap|Line Numbers
  1.  
  2. public class MyProgram {
  3.  public static void main(String[] args) {
  4.   //You program logic goes here
  5.  }
  6. }
  7.  
Now you just write your logic in the main method.
Mar 9 '07 #9
djtosh
18
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.
Mar 9 '07 #10
r035198x
13,262 8TB
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
Expand|Select|Wrap|Line Numbers
  1.  double area = n * n;
If you have N squares then the total area is

Expand|Select|Wrap|Line Numbers
  1.  double totalArea = N * n * n;
Mar 9 '07 #11
djtosh
18
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
Mar 9 '07 #12
r035198x
13,262 8TB
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

Expand|Select|Wrap|Line Numbers
  1.  
  2. double area = 0;
  3.   int L = 3;
  4.   int N = 3;
  5.   int I = 2;
  6.   for(int i = 0 ; i < N; i ++) {
  7.    area = area + (L * L);
  8.    L = L + I;
  9.   }
  10.   System.out.println(area);
  11.  
Mar 10 '07 #13
djtosh
18
thanks mate ill try that out it looks similar to what i thought i had to do, thanks very much
Mar 10 '07 #14
r035198x
13,262 8TB
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.
Mar 10 '07 #15
djtosh
18
Expand|Select|Wrap|Line Numbers
  1.  { 
  2.     static Scanner data_input = new Scanner(System.in);
  3.  
  4.     // Method to calculate the area of a square
  5.     static void square(String [] args)
  6.     {
  7.      int l, n, i, t, result = 0;
  8.         boolean quit;
  9.  
  10.         // Get the length
  11.         System.out.print("Enter the length of a side of the square: ");
  12.         l = data_input.nextInt();
  13.  
  14.                 while(l <=0)
  15.     {
  16.  
  17.         // Output error message
  18.         System.out.println("Length must be greater than 0");
  19.  
  20.         // Get length
  21.         System.out.print("Enter the length: ");
  22.         l = data_input.nextInt();
  23.     }
  24.      // Get the number of squares
  25.         System.out.print("Enter the number of squares you wish to calculate: ");
  26.         n = data_input.nextInt();
  27.  
  28.             if (n <=0)
  29.         {
  30.         System.out.println("That number was not valid:");
  31.         quit = true;
  32.  
  33.         // Get the number of squares
  34.         System.out.print("Enter the number of squares you wish to calculate: ");
  35.         n = data_input.nextInt();
  36.         }
  37.  
  38.         // Get the Increment
  39.         System.out.print("Enter the size increment: ");
  40.         i = data_input.nextInt();
  41.  
  42.             if (i <=0)
  43.         {
  44.         System.out.println("That number was not valid:");
  45.         quit = true;
  46.  
  47.         // Get the Increment
  48.         System.out.print("Enter the size increment: ");
  49.         i = data_input.nextInt();
  50.         }
  51.  
  52.         // Add the numbers
  53.  
  54.         for(t = 0 ; t < n; t++ )
  55.         {
  56. result = (l * l);
  57.         // Display the result
  58.         System.out.print(l + " * ");
  59. System.out.print(l + " = ");
  60. System.out.println(result);
  61.         l = l + i;
  62. }
  63.  
  64.  
  65.  
  66.     }
  67.  
Mar 14 '07 #16
djtosh
18
this is how my code looked in the end and it worked perfectly, i used the array/loop that you gave me, it just needed slight rearrangement, thanks
Mar 14 '07 #17
r035198x
13,262 8TB
this is how my code looked in the end and it worked perfectly, i used the array/loop that you gave me, it just needed slight rearrangement, thanks
Good to hear that .
Mar 15 '07 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Nicholas Pappas | last post by:
Hello all. I am trying to write a Java3D loader for a geometry file from a game, which has Unicode characters (Korean) in it. I wrote the loader and it works in Windows, but I recently brushed...
147
by: Sateesh | last post by:
Hi, I am a beginner in Python, and am wondering what is it about the indentation in Python, without which python scripts do not work properly. Why can't the indentation not so strict so as to give...
5
by: mr.iali | last post by:
Hi Everyone I would like to get into software developent using a programming language like c++, java or pl/sql for oracle. I have no idea where to start from. Which language is there more...
7
by: dh.evolutionnext | last post by:
Hey, I am an instructor and I have an XML class coming up. I would just like to know a good, easy, and intuitive XML editor that does validating, code completion, etc. I usually use NetBeans but...
25
by: redefined.horizons | last post by:
I've traditionally been a Java developer, although I play around with LISP. I recently migrated to Linux and I was exploring Mono as an option for development on Linux. However, I've had some...
458
by: wellstone9912 | last post by:
Java programmers seem to always be whining about how confusing and overly complex C++ appears to them. I would like to introduce an explanation for this. Is it possible that Java programmers...
63
by: John Salerno | last post by:
I know there's a request for a good IDE at least once a week on the ng, but hopefully this question is a little different. I'm looking for suggestions for a good cross-platform text editor (which...
12
by: BillJosephson | last post by:
Hi all. I am trying to use jEdit, but can't seem to download any plugins. I go to Plugin Manager, and select Download options. I update the mirro and can see lots of servers. I select the first...
6
by: Bob Palank | last post by:
I'm considering using VJ# in a first programming course in addition to or in place of JBuilder and the J2SE. Given install problems other students have had, VJ# seems like a nice alternative. I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.