Results 1 to 9 of 9
  1. #1
    Valerie1067 is offline Member
    Join Date
    Mar 2012
    Location
    Palestine Texas
    Posts
    18
    Rep Power
    0

    Default Mod and If Statement

    Hi there,

    For some reason I can't get my mod to make my variable in the if statement to go up a number. Any help would be appreciated!! it is suppose to add the remainder (if any) and make the numberOfRolls go up by one, did I not do set it correctly? Do you need to see more of the code? 35 is the sqft of the roll btw, and you can only order a whole roll at a time.

    Java Code:
    numberOfRolls = (roomExtra/35.0)+(roomExtra%35.0);
    		if(numberOfRolls >0)
    			{
    				numberOfRolls = numberOfRolls +1;
    			}
    				System.out.println("The total number of rolls needed: " + f.format(numberOfRolls));

  2. #2
    subzero1012 is offline Member
    Join Date
    Feb 2012
    Location
    Phoenix, AZ
    Posts
    26
    Rep Power
    0

    Default Re: Mod and If Statement

    Hello,
    I'm sorry, but the problem statement doesn't appear to be very clear to me. As long as your entire code isn't too long, could you please paste the entire code? I mean, if roomExtra was 71, then numberOfRolls would be 2+1 = 3. Then add another?

  3. #3
    Valerie1067 is offline Member
    Join Date
    Mar 2012
    Location
    Palestine Texas
    Posts
    18
    Rep Power
    0

    Default Re: Mod and If Statement

    Absolutely! Thank you so much for looking at it!!

    Java Code:
    import java.util.Scanner;
    import java.text.DecimalFormat;
    
    public class WallpaperRolls
    	{
    	public static void main(String[] args)
    		{
    	//Create Scanner object
    	Scanner input = new Scanner(System.in);
    
    	//Create variables
    	float lengthOfRoom;
    	float heightOfRoom;
    	float widthOfRoom;
    	double roomArea, totalArea;
    	double roomExtra; 
    	double numberOfRolls;
    	double totalCost, pricePerRoll;
    
    	DecimalFormat f = new DecimalFormat("0.00");
    
    	//Get room dimensions
    	System.out.print("What is the length of the room (in ft)?: ");
    	lengthOfRoom = input.nextFloat();
    
    	System.out.print("What is the height of the room (in ft)?: ");
    	heightOfRoom = input.nextFloat();
    	System.out.print("What is the width of room (in ft)?: ");
    	widthOfRoom = input.nextFloat();
    
    	// Get price per roll
    	System.out.print("What is the price of the wallpaper?:$");
    	pricePerRoll = input.nextDouble();
    
    	//Calculate area
    	roomArea = ((2 * lengthOfRoom * heightOfRoom) + (2 * lengthOfRoom * widthOfRoom));
    
    	//Calculate mistakes
    	roomExtra = ( roomArea*1.10);
    
    	//Calculate number of rolls
    	numberOfRolls = (roomExtra/35.0)+(roomExtra%35.0);
    		if(numberOfRolls >0)
    			{
    				numberOfRolls = numberOfRolls +1;
    			}
    				System.out.println("The total number of rolls needed: " + f.format(numberOfRolls));
    			
    	//Calculate total area
    	totalArea = roomArea;
    	System.out.println("The total area of room is " + f.format(totalArea));
    
    	//Calculate total cost
    	totalCost = (numberOfRolls * pricePerRoll);
    	System.out.println("The total cost of wallpaper:$" + f.format(totalCost));
    
    	}	
    }

  4. #4
    subzero1012 is offline Member
    Join Date
    Feb 2012
    Location
    Phoenix, AZ
    Posts
    26
    Rep Power
    0

    Default Re: Mod and If Statement

    Thanks for posting the code. It appears to work as required for me (adds an additional roll inside the if statement). The result I got was 9.14 rolls. I used the following inputs as test conditions.

    length = 5
    width = 5
    height = 5

    roomExtra = 110

    110/35 = 3.14
    110%35 = 5

    3.14 + 5 = 8.14

  5. #5
    Valerie1067 is offline Member
    Join Date
    Mar 2012
    Location
    Palestine Texas
    Posts
    18
    Rep Power
    0

    Default Re: Mod and If Statement

    Ok! thank you very much! I guess I just thought that it should be a whole number and not a decimal number, so I thought that it wasn't working properly. thank you so much for your help!

  6. #6
    subzero1012 is offline Member
    Join Date
    Feb 2012
    Location
    Phoenix, AZ
    Posts
    26
    Rep Power
    0

    Default Re: Mod and If Statement

    I've looked at your code a little more closely and something doesn't make sense to me. For example, if my roomExtra was 72 sqft, you would really just need 3 rolls, right? If so, your code would calculate that you would need 5 rolls. Am I missing something here?

  7. #7
    Valerie1067 is offline Member
    Join Date
    Mar 2012
    Location
    Palestine Texas
    Posts
    18
    Rep Power
    0

    Default Re: Mod and If Statement

    hhhmmm...I didnt realize that! thank you for pointing that out, any suggestions? i am not sure how that is happening. I am very new to Java. Thank you so much for catching that!

  8. #8
    subzero1012 is offline Member
    Join Date
    Feb 2012
    Location
    Phoenix, AZ
    Posts
    26
    Rep Power
    0

    Default Re: Mod and If Statement

    //Calculate number of rolls
    numberOfRolls = (int) (roomExtra/35.0); //round down to integer
    if(roomExtra%35.0 >0) if remainder, add a roll
    { numberOfRolls = numberOfRolls +1; }

  9. #9
    Valerie1067 is offline Member
    Join Date
    Mar 2012
    Location
    Palestine Texas
    Posts
    18
    Rep Power
    0

    Default Re: Mod and If Statement

    You are AMAZING!!! thank you so much!!!!!! I can't tell you how much I appreciate it!! have a wonderful night!

Similar Threads

  1. for statement
    By mattcash83 in forum New To Java
    Replies: 8
    Last Post: 10-18-2011, 03:48 AM
  2. need help in sql statement
    By chyeeqi in forum JDBC
    Replies: 6
    Last Post: 03-28-2010, 08:49 PM
  3. if statement help please!!
    By soc86 in forum New To Java
    Replies: 5
    Last Post: 12-02-2008, 03:56 PM
  4. If statement, please help??
    By soc86 in forum New To Java
    Replies: 5
    Last Post: 11-23-2008, 03:58 PM
  5. Statement or Prepared Statement ?
    By paty in forum JDBC
    Replies: 3
    Last Post: 08-01-2007, 05:45 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
  •