Results 1 to 3 of 3
Thread: if statements inside of an if
- 10-26-2010, 10:18 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 1
- Rep Power
- 0
if statements inside of an if
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class LawnMowingClass
{
public static void main(String[] args)
{
float lengthFeet;
float widthFeet;
int payment;
float weekly = 0;
float square;
float season = 0;
float totalCost = 0;
int serviceFee = 0;
lengthFeet = Float.parseFloat(JOptionPane.showInputDialog("What is the length of your yard?"));
if (lengthFeet < 10 || lengthFeet > 100)
{
lengthFeet = Float.parseFloat(JOptionPane.showInputDialog("ERRO R -- YARD MUST BE BETWEEN 10-100 FT LONG \nWhat is the length of your yard?"));
}
widthFeet = Float.parseFloat(JOptionPane.showInputDialog("What is the width of your yard?"));
if (widthFeet < 10 || widthFeet > 100)
{
widthFeet = Float.parseFloat(JOptionPane.showInputDialog("ERRO R -- YARD MUST BE BETWEEN 10-100 FT WIDE \nWhat is the width of your yard?"));
}
payment = Integer.parseInt(JOptionPane.showInputDialog("Do you want to pay 1, 2, or 20 times a season?"));
square = lengthFeet * widthFeet;
if (square < 500)
{
weekly = 25;
season = weekly * 20;
if (payment == 1)
{
serviceFee = 0;
}
}
if (square < 1000 || square >= 500)
{
weekly = 35;
season = weekly * 20;
if (payment == 2)
{
serviceFee = 5 * 20;
}
}
if (square >= 1000)
{
weekly = 50;
season = weekly * 20;
if (payment == 20)
{
serviceFee = 3 * 20;
}
}
DecimalFormat formatter = new DecimalFormat("0.00");
DecimalFormat footage = new DecimalFormat("000");
totalCost = season + serviceFee;
JOptionPane.showMessageDialog(null,"The square footage is: " +footage.format(square)
+"\n The weekly charge would be: $" +formatter.format(weekly)
+"\n The seasonal charge would be: $" +formatter.format(season)
+"\n The service fee is: $" +formatter.format(serviceFee)
+"\n The total cost for the season is: $" +formatter.format(totalCost));
System.exit(0);
}
}
this is what i have so far but i cannot get a service to come up if the user enters a payment of 20 times any ideas?
- 10-27-2010, 09:38 AM #2
Actually I dont know exactly what you need .
However, you better use if else instead of if.Mak
(Living @ Virtual World)
- 10-27-2010, 01:18 PM #3
Similar Threads
-
Help with IF Statements and GUI
By university123 in forum New To JavaReplies: 8Last Post: 10-14-2010, 04:38 AM -
if else if statements
By Allspark in forum New To JavaReplies: 9Last Post: 09-28-2010, 06:50 PM -
Help with if else statements
By np2392 in forum New To JavaReplies: 2Last Post: 09-24-2010, 01:25 AM -
if else statements
By sweetpea123 in forum New To JavaReplies: 4Last Post: 04-12-2010, 07:02 PM -
Help with if-else statements
By porchrat in forum New To JavaReplies: 4Last Post: 03-23-2009, 04:24 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks