Results 1 to 3 of 3
  1. #1
    thesthrncmfrt is offline Member
    Join Date
    Oct 2010
    Posts
    1
    Rep Power
    0

    Default 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?

  2. #2
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    450
    Rep Power
    6

    Default

    Actually I dont know exactly what you need .

    However, you better use if else instead of if.
    Mak
    (Living @ Virtual World)

  3. #3
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by thesthrncmfrt View Post
    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?

    analyzing your code you can see that the if-statement payment == 20 is evaluated ONLY when square >= 1000 is true. so entering values of length and width that result in a square >= 1000 to be true also your "20 times" will run.

Similar Threads

  1. Help with IF Statements and GUI
    By university123 in forum New To Java
    Replies: 8
    Last Post: 10-14-2010, 05:38 AM
  2. if else if statements
    By Allspark in forum New To Java
    Replies: 9
    Last Post: 09-28-2010, 07:50 PM
  3. Help with if else statements
    By np2392 in forum New To Java
    Replies: 2
    Last Post: 09-24-2010, 02:25 AM
  4. if else statements
    By sweetpea123 in forum New To Java
    Replies: 4
    Last Post: 04-12-2010, 08:02 PM
  5. Help with if-else statements
    By porchrat in forum New To Java
    Replies: 4
    Last Post: 03-23-2009, 05:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •