Page 1 of 2 12 LastLast
Results 1 to 20 of 27
  1. #1
    einstein1234 is offline Member
    Join Date
    Apr 2009
    Posts
    34
    Rep Power
    0

    Default [SOLVED] cant figure this program out..help

    hi im trying to Write a program called PaintersHelperSplit

    It does exactly what my previous PaintersHelper program does.

    In this version it says do the calculations in a helper method called computeGallons. Here is the method header for it:

    static int computeGallons(int height, int length, int width, int doors, int smWindows, int lgWindows) {

    Gather the data you need (6 numbers) in the main method. Then use computeGallons to… compute the gallons. ????

    I have to Print the answer to the screen in the main method.

    but some of the local variables that I have to declare in main will not be needed there now. They will be needed in computeGallons instead.


    ok so heres my original painterhelpers program__

    /* This program calculates the number of gallons of paint needed to paint a room.
    Programmer:
    Date: April 4, 2009
    */

    import java.util.Scanner;

    public class PaintersHelper {
    static float DOOR_SIZE = 15.0f;
    static float SMALL_WINDOW_SIZE =2.0f;
    static float LARGE_WINDOW_SIZE = 5.0f;
    static float SQ_FT_PER_GALLON = 375.0f;
    static float netsquarefeet;
    static float grosssquarefeet;
    public static void main(String[] args) {

    // declare all variables to be used
    int width, length, height, doors, lgwindows, smwindows;
    float gallons, subtraction;

    // give welcome and instructions to user
    System.out.println("Welcome to the painters Helper");

    Scanner input = new Scanner (System.in);

    // prompt user for the room's width
    System.out.println("Please enter the room's width:");
    width = input.nextInt();

    // prompt user for the room's length
    System.out.println("Please enter the room's length:");
    length = input.nextInt();

    // prompt user for the room's height
    System.out.println("Please enter the room's height:");
    height = input.nextInt();

    // prompt user for the number of doors
    System.out.println("Please enter the number of doors:");
    doors = input.nextInt();

    // prompt user for the number of small windows
    System.out.println("Please enter the the number of small windows:");
    smwindows = input.nextInt();

    // prompt user for the number of large windows
    System.out.println("Please enter the number of large windows:");
    lgwindows = input.nextInt();

    // gross square feet = height * 2 * (length + width)
    grosssquarefeet = height * 2 * ( length + width);


    // subtractions is the sum of:
    subtraction = (doors * DOOR_SIZE) + (lgwindows * LARGE_WINDOW_SIZE) + (smwindows * SMALL_WINDOW_SIZE);
    // number of doors * door size
    // number of lgWindows * lgWindow size
    // number of smWindows * smWindow size
    // net square feet = gross square feet - subtractions
    netsquarefeet = grosssquarefeet - subtraction;
    // gallons = netSqFt / SQ_FT_PER_GALLON rounded to the nearest gallon

    gallons = netsquarefeet / SQ_FT_PER_GALLON;
    // display the answer.


    System.out.println("You will need about " + gallons + "gallons of paint for your room.");


    } // end of method main

    } // end of class PaintersHelper

  2. #2
    Tshegofatsom is offline Member
    Join Date
    Apr 2009
    Location
    Pretoria, Gauteng, South Africa
    Posts
    43
    Rep Power
    0

    Default

    Hi there
    The method signature: "static int computeGallons(int height, int length, int width, int doors, int smWindows, int lgWindows)" tells you that the Main program will pass 6 values to the "computeGallons" method. after that every calculations will be performed in the method and an integer representing the Gallons will be returned (we know this because the method is of type integer). This means that all the temporary variables you needed to calculate, will now be in the computeGallons method. In main, the variables that will be needed are the ones to capture values from the prompt. It is up to you to decide whether you want to hold the results of the method computeGallons inside a variable before you display them or if you will just call the method in your println function.
    Let me know if you understand. Good luck
    Tshegofatso Manakana
    a.k.a Untouchable ™

  3. #3
    einstein1234 is offline Member
    Join Date
    Apr 2009
    Posts
    34
    Rep Power
    0

    Default

    i understand a little of what you just explained, however theres still a confusion here, can you start me off.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I would recommend that you read up on creating methods in your textbook or a decent tutorial and then give it a try on your own first. Here are some of the Sun tutorials on this subject:
    Defining a method
    passing arguments to a method
    Returning a value from a method

    Best of luck

  5. #5
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default

    Einstein... I would suggest starting small and understanding how a method works. Review the links that Furball has in his post. Once you have a couple of successful examples of methods compiled and working, then you can start to tackle on changing your program to include a method.
    A sample (color coded):

    Calling the method:
    Java Code:
    [B][COLOR="Red"]int myVariable[/COLOR][/B] = [B][COLOR="YellowGreen"]myMethod[/COLOR][/B]([B][COLOR="Blue"]myIntParameter1, myIntParameter2[/COLOR][/B]);
    The method:
    Java Code:
    public static [B][COLOR="Red"]int[/COLOR][/B] [B][COLOR="yellowgreen"]myMethod[/COLOR][/B]([B][COLOR="blue"]int number1, int number2[/COLOR][/B])
    {
     int myResult = number1 + number2;
     return [B][COLOR="red"]myResult[/COLOR][/B];
    }
    The red is what the method is going to return
    the blue is the parameters that are passed to the method (going to be six in your case)

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  6. #6
    einstein1234 is offline Member
    Join Date
    Apr 2009
    Posts
    34
    Rep Power
    0

    Default

    thanx man, ill look that over and give it a try.

  7. #7
    einstein1234 is offline Member
    Join Date
    Apr 2009
    Posts
    34
    Rep Power
    0

    Default

    wowo dis is hard im stuck on the reading fubarable put up. i dont know wat im doing here.

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I think that you've got to learn things that the forum just can't teach you. As I've mentioned before, I think that you should to talk to your teacher asap. One-on-one help will offer your best chance of you up to speed as quickly as possible, either that or in all seriousness and not meant as an insult, consider dropping the class.

    Best of luck.

  9. #9
    einstein1234 is offline Member
    Join Date
    Apr 2009
    Posts
    34
    Rep Power
    0

    Default

    wow, thats not going to help by trying to discourage me, why cant you make a comment where you can actually help me in finishing this assingment, i dont really want the answer, but juss a lil assistance here would be good.

  10. #10
    einstein1234 is offline Member
    Join Date
    Apr 2009
    Posts
    34
    Rep Power
    0

    Default

    wow, yea i agree but dont you think ur being a lil harsh here, i mean, u no, i dont know, anyways can anyone help here.

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    It's not that I don't want to help you finish the assignment, it's that our doing the assignment won't help you learn, and what you need more than anything is to understand the concepts. The best way to do that fast is either through hard study or through one-on-one tutoring.

    Chris has given good method examples above. Does this information help you? Do you have any questions about his examples that we can answer?

  12. #12
    einstein1234 is offline Member
    Join Date
    Apr 2009
    Posts
    34
    Rep Power
    0

    Default

    lol, this person here seems to hate you or somthin is goin on here, anyways, chris is very helpfull, and you juss can seem to give me an example or instead of helping me through this, you insult me by saying i should drop the class, and thats not helpfull at all, so i dont know whats going on?? juss need a lil help here dats all.

  13. #13
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    What specific question do you have? If you pose an answerable question, I'll do my best to answer it, but again it has to be specific.

  14. #14
    einstein1234 is offline Member
    Join Date
    Apr 2009
    Posts
    34
    Rep Power
    0

    Default

    ok so heres my original painterhelpers program__

    /* This program calculates the number of gallons of paint needed to paint a room.
    Programmer:
    Date: April 4, 2009
    */

    import java.util.Scanner;

    public class PaintersHelper {
    static float DOOR_SIZE = 15.0f;
    static float SMALL_WINDOW_SIZE =2.0f;
    static float LARGE_WINDOW_SIZE = 5.0f;
    static float SQ_FT_PER_GALLON = 375.0f;
    static float netsquarefeet;
    static float grosssquarefeet;
    public static void main(String[] args) {

    // declare all variables to be used
    int width, length, height, doors, lgwindows, smwindows;
    float gallons, subtraction;

    // give welcome and instructions to user
    System.out.println("Welcome to the painters Helper");

    Scanner input = new Scanner (System.in);

    // prompt user for the room's width
    System.out.println("Please enter the room's width:");
    width = input.nextInt();

    // prompt user for the room's length
    System.out.println("Please enter the room's length:");
    length = input.nextInt();

    // prompt user for the room's height
    System.out.println("Please enter the room's height:");
    height = input.nextInt();

    // prompt user for the number of doors
    System.out.println("Please enter the number of doors:");
    doors = input.nextInt();

    // prompt user for the number of small windows
    System.out.println("Please enter the the number of small windows:");
    smwindows = input.nextInt();

    // prompt user for the number of large windows
    System.out.println("Please enter the number of large windows:");
    lgwindows = input.nextInt();

    // gross square feet = height * 2 * (length + width)
    grosssquarefeet = height * 2 * ( length + width);


    // subtractions is the sum of:
    subtraction = (doors * DOOR_SIZE) + (lgwindows * LARGE_WINDOW_SIZE) + (smwindows * SMALL_WINDOW_SIZE);
    // number of doors * door size
    // number of lgWindows * lgWindow size
    // number of smWindows * smWindow size
    // net square feet = gross square feet - subtractions
    netsquarefeet = grosssquarefeet - subtraction;
    // gallons = netSqFt / SQ_FT_PER_GALLON rounded to the nearest gallon

    gallons = netsquarefeet / SQ_FT_PER_GALLON;
    // display the answer.


    System.out.println("You will need about " + gallons + "gallons of paint for your room.");


    } // end of method main

    } // end of class PaintersHelper


    ok so how do i do the calculations in a helper method called computeGallons. Here is the method header for it:

    static int computeGallons(int height, int length, int width, int doors, int smWindows, int lgWindows) {

    Gather the data you need (6 numbers) in the main method. Then use computeGallons to… compute the gallons. ????

    I have to Print the answer to the screen in the main method.

  15. #15
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    this part:
    Java Code:
    static int computeGallons(int height, int length, int width, int doors, int smWindows, int lgWindows) {
    //..
    tells you that you have to create a method with this signature that takes these input values and returns the result in an int. Your method will look like this:

    Java Code:
    static int computeGallons(int height, int length, int width, int doors, int smWindows, int lgWindows) {
      int gallons = //.... do calculation here
    
      return gallons;  // return the result of the calculation
    }
    and the calculations in this method are the exact same as the ones used in your previous program in the main method

    The main method gets the input just as you did before, but instead of doing the calculations in the main method, you pass all the data input in by the user into a call of this method:
    Java Code:
      public static void main(String[] args)
      {
        int width, length, height, doors, lgwindows, smwindows;
        int gallons, subtraction;
        System.out.println("Welcome to the painters Helper");
        Scanner input = new Scanner(System.in);
    
        System.out.println("Please enter the room's width:");
        width = input.nextInt();
    
        System.out.println("Please enter the room's length:");
        length = input.nextInt();
        //........etc.... code deleted for brevity
    
        
        gallons = computeGallons(/*  pass all parameters here */);
    
        System.out.println("You will need about " + gallons
            + "gallons of paint for your room.");
    
      }

  16. #16
    Tshegofatsom is offline Member
    Join Date
    Apr 2009
    Location
    Pretoria, Gauteng, South Africa
    Posts
    43
    Rep Power
    0

    Default

    Einstein, do you understand what the program does? I mean your original program. Are you the one who coded it? Do you understand why you did what ever is in that program?
    Tshegofatso Manakana
    a.k.a Untouchable ™

  17. #17
    einstein1234 is offline Member
    Join Date
    Apr 2009
    Posts
    34
    Rep Power
    0

    Default

    yea the program is suppose to calculates the number of gallons of paint needed to paint a room. i did it myself through hard work and reading many chapters, but now the instructor wants me to do the calculations in a helper method called computeGallons. its complicated but i am recieving help from chris, and fubarble. im getting there, juss need a lil assistance dats all, and im trying very hard here. thanx

  18. #18
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default

    Einstein... all your calculations to find out how many gallons of paint is needed, has to be done in the method. You have call the method. First thing to do is figure out what the method is going to return. According to the specifications, it's going to return the amount of gallons which is an int. So you need to define an int variable to hold the gallons (totalGallons?). Then you need to call the method. You already have the name of the method and what parameters need to be specified so it would look semthing like:
    Java Code:
    int totalGallons = computeGallons(height, length, width, doors, smWindows, lgWindows);
    Now, that call above will replace ALL the caculations you did in the main to get the total amount of gallons and all those caculations will be placed in the method.
    So far so good?

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  19. #19
    einstein1234 is offline Member
    Join Date
    Apr 2009
    Posts
    34
    Rep Power
    0

    Default

    so far so good

  20. #20
    einstein1234 is offline Member
    Join Date
    Apr 2009
    Posts
    34
    Rep Power
    0

Page 1 of 2 12 LastLast

Similar Threads

  1. I couldn’t figure out how to do this please help!
    By afrttoh in forum New To Java
    Replies: 5
    Last Post: 11-19-2008, 08:21 PM
  2. Replies: 2
    Last Post: 11-08-2008, 04:58 AM
  3. Replies: 2
    Last Post: 07-11-2008, 09:41 AM
  4. Seems so simple yet I can't figure it out!
    By adamhaviland in forum New To Java
    Replies: 1
    Last Post: 11-03-2007, 06:26 PM
  5. I can't figure this out
    By silvia in forum New To Java
    Replies: 3
    Last Post: 07-20-2007, 04:38 AM

Posting Permissions

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