473,387 Members | 1,420 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,387 software developers and data experts.

Help with program (sorry im a noob)

6
I can't figure out why 'display' in the main method wont show in my output. Any help will be appreciated.
Expand|Select|Wrap|Line Numbers
  1.    import javax.swing.JOptionPane;
  2.     public class lab006 {
  3.  
  4.  
  5.  
  6.        public static void main  (String [ ] args) {
  7.          int numRoom;
  8.          numRoom = number();
  9.          String display="";
  10.          int numberOfRooms = 0;
  11.          int length=0;
  12.          int width=0;
  13.          String name="";
  14.          int area=0;
  15.          int totalArea=0;
  16.  
  17.          for(int i = 0; i < numRoom; i++) {
  18.  
  19.             name = JOptionPane.showInputDialog("Enter name of room");
  20.  
  21.             do {
  22.                width =Integer.parseInt(JOptionPane.showInputDialog("The width of " + name + " --in feet")); 
  23.             } while(width <= 0 || width >= 30);     
  24.             do {
  25.                length =Integer.parseInt(JOptionPane.showInputDialog("The length of " + name + " --in feet")); 
  26.             } while(length <= 0 || length >= 30);     
  27.             area=length*width;
  28.             totalArea+=area;
  29.  
  30.             display+= name + area + "\n\n\n";
  31.          }
  32.          finalOutput(display, totalArea);
  33.  
  34.       }
  35.  
  36.  
  37.        public static int number () {
  38.          int numberOfRooms=0;
  39.          do {
  40.             numberOfRooms = Integer.parseInt(JOptionPane.showInputDialog("How many rooms in the house?"));//display message box to get the number of rooms
  41.          } while (numberOfRooms >= 10 || numberOfRooms <= 0);
  42.          return numberOfRooms;
  43.       }
  44.  
  45.  
  46.        public static void finalOutput(String output, int totalArea)
  47.       {
  48.  
  49.          output="Room          |        Area\n";
  50.  
  51.          output += "Total Square Footage: " + totalArea  + " square feet";
  52.  
  53.          JOptionPane.showMessageDialog(null, output);
  54.  
  55.       }
  56.    }
Apr 23 '07 #1
5 1432
JosAH
11,448 Expert 8TB
You carefully build up the display string here:
Expand|Select|Wrap|Line Numbers
  1.  
  2.             display+= name + area + "\n\n\n";
Finally you pass it to yout finalOutput method where you do this:
Expand|Select|Wrap|Line Numbers
  1.        public static void finalOutput(String output, int totalArea)
  2.       {
  3.  
  4.          output="Room          |        Area\n";
This means that you simply discard the previous content of the string. Get it?

kind regards,

Jos
Apr 24 '07 #2
r035198x
13,262 8TB
I can't figure out why 'display' in the main method wont show in my output. Any help will be appreciated.
Expand|Select|Wrap|Line Numbers
  1. import javax.swing.JOptionPane;
  2. public class lab006 {
  3.  
  4.  
  5.  
  6. public static void main (String [ ] args) {
  7. int numRoom;
  8. numRoom = number();
  9. String display="";
  10. int numberOfRooms = 0;
  11. int length=0;
  12. int width=0;
  13. String name="";
  14. int area=0;
  15. int totalArea=0;
  16.  
  17. for(int i = 0; i < numRoom; i++) {
  18.  
  19. name = JOptionPane.showInputDialog("Enter name of room");
  20.  
  21. do {
  22. width =Integer.parseInt(JOptionPane.showInputDialog("The width of " + name + " --in feet")); 
  23. } while(width <= 0 || width >= 30); 
  24. do {
  25. length =Integer.parseInt(JOptionPane.showInputDialog("The length of " + name + " --in feet")); 
  26. } while(length <= 0 || length >= 30); 
  27. area=length*width;
  28. totalArea+=area;
  29.  
  30. display+= name + area + "\n\n\n";
  31. }
  32. finalOutput(display, totalArea);
  33.  
  34. }
  35.  
  36.  
  37. public static int number () {
  38. int numberOfRooms=0;
  39. do {
  40. numberOfRooms = Integer.parseInt(JOptionPane.showInputDialog("How many rooms in the house?"));//display message box to get the number of rooms
  41. } while (numberOfRooms >= 10 || numberOfRooms <= 0);
  42. return numberOfRooms;
  43. }
  44.  
  45.  
  46. public static void finalOutput(String output, int totalArea)
  47. {
  48.  
  49. output="Room | Area\n";
  50.  
  51. output += "Total Square Footage: " + totalArea + " square feet";
  52.  
  53. JOptionPane.showMessageDialog(null, output);
  54.  
  55. }
  56. }
1.)Please use code tags when posting code
2.)
Expand|Select|Wrap|Line Numbers
  1. output="Room | Area\n";
  2.  
sets the variable output to ="Room | Area\n". Any value that was previously in output is thrown away.
Apr 24 '07 #3
baden
6
I get what you guys are saying but how would I go about fixing it.
Apr 24 '07 #4
JosAH
11,448 Expert 8TB
I get what you guys are saying but how would I go about fixing it.
How about changing this line:
Expand|Select|Wrap|Line Numbers
  1. output="Room          |        Area\n";
to this:
Expand|Select|Wrap|Line Numbers
  1. output="Room          |        Area\n"+output;
kind regards,

Jos
Apr 25 '07 #5
baden
6
Thanks Got IT!
Apr 26 '07 #6

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

Similar topics

6
by: Ivan Shevanski | last post by:
Here's a noob question for everyone (I'm not sure if my first message got through, is had a "suspicious header" so sorry for double post is so), is there a way to turn off syntax warnings or just...
7
by: mastern200 | last post by:
For Homework, i have to debug a program (I am a noob!) it is a voting program where you put in the amount of votes a certain candidate gets and evaluates by showing how many votes, what percentage of...
4
by: Signeg | last post by:
Hey guys, I have some work for university and i never used C++ in my life so i'm kinda lost.. But i've still managed to write something woth it. But too bad for me the prog does compile and lunch...
12
by: stormsender | last post by:
Hi there, I'm a noob to javascript, so was hopping to find some help here... I believe that what I need is simple, still haven't found any solution. I have a website serving ads, and links...
5
by: Hydrogenfussion | last post by:
Hello and thank you for reading this. I have just started to learn C++ from www.cprogramming.com,its a great site! But i do not understand some of the terms. I am using Dev-C++. Can you tell me...
10
by: Pavel Shved | last post by:
Is there a program of wide use that automatically extracts template parameters requirements from source code of template functions? I mean the following: assume we have a template function that...
3
by: Dew | last post by:
Hello, iam new to programming, and ive been given a task in my Uni to complete certain exercises but i found it very difficulty to solve them. I was wandering if there is someone who can help me...
4
by: larry | last post by:
Ok I'm a Python noob, been doing OK so far, working on a data conversion program and want to create some character image files from an 8-bit ROM file. Creating the image I've got down, I open...
5
by: xi4n9 | last post by:
im a newbie to action script stuff in flash,currently needed help on my 2nd flash annimation to work out. i would like to know how to pick up an item and put in down as i dont want to drag the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.