Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 22nd, 2005, 08:18 PM
jrg0088 jrg0088 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 2 jrg0088 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 32 m 42 sec
Reputation Power: 0
Question Please I need help using for loop (int=0;int<10;int++)

Could you please help me and let me know how i can write this program using for loop?
Community hospital needs a program to compute and print a statement for each patient. Charges for each days are as follows:
A. room charge
a. Private Room:$125.00
b. Semiprivate Room: $95.00
c. ward:$75.00
B. Telephone Charge: $1.75
C. Television Charge:$3.50
Write a program to get a line of data from keyboard, compute the patients bill, and print the appropriate statements.
Could please let me know how i can write this program using for loop. I need this program using for loop


import javax.swing.JOptionPane;

publicclass hospital
{
publicstaticvoid main (String [] args)
{
double numofday=0,rc=0,pr=125,spr=95,ward=75,a,b,c,teleph onecharge=1.75,televisioncharge=3.5;
finaldouble tc=1.75,tv=3.50;
String day=JOptionPane.showInputDialog(
null,"Enter number of day","#day",JOptionPane.QUESTION_MESSAGE);
numofday=Integer.parseInt (day);

String type=JOptionPane.showInputDialog(
null,"Enter Room Charge(1,2,3)","Room",JOptionPane.QUESTION_MESSAGE);
a=Integer.parseInt (type);

if (a==1)
rc=pr*numofday;

elseif (a==2)
rc=spr*numofday;

elseif (a==3)
rc=ward*numofday;

String telephone=JOptionPane.showInputDialog(
null,"Enter 4 for TelePhone charge ","TC",JOptionPane.QUESTION_MESSAGE);
b=Integer.parseInt(telephone);
if(b==4)
telephonecharge=numofday*tc;

String television=JOptionPane.showInputDialog(
null,"Enter 5 for Television Charge", "TV",JOptionPane.QUESTION_MESSAGE);
c=Integer.parseInt(television);

if (c==5);
televisioncharge=numofday*tv;

JOptionPane.showMessageDialog (
null, "numofday" +numofday+ "\n room charge $" +rc+ "\n private room $" +pr+ "\n semi private room$" +spr+ "\n ward $" +ward+ "\n TelePhone Charge $"+tc+ "\n Television Charge "+tv+ "\n thank you for coming \n Remember be healthy ","result",JOptionPane.INFORMATION_MESSAGE);
System.exit (0);
}
}







Reply With Quote
  #2  
Old March 23rd, 2005, 03:38 AM
gertcuppens's Avatar
gertcuppens gertcuppens is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 118 gertcuppens User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 28 m
Reputation Power: 5
The only way I see to get a for loop inside your program, is to
do the following :

Code:
 String question : 
for (int i = 0; i++; i <= 5)
  {
/* compose your question first depending on the value of i */
  switch (i)
  {
  case 1 :
	  question =  "enter number of day"; 
	  break; 
  case 2 : ...
  }
String answer=JOptionPane.showInputDialog(null,question ,JOptionPane.QUESTION_MESSAGE);
answerInt=Integer.parseInt (answer);
/* calculate depending on the value of i */ 
 switch (i)
  {
 case 1 : numofday=answer;
  break;
  case 2 : ...
}









Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Please I need help using for loop (int=0;int<10;int++)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT