|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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); } } |
|
#2
|
||||
|
||||
|
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 : ...
}
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > Please I need help using for loop (int=0;int<10;int++) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|