Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: beginner java program help

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default beginner java program help

    hi i recently started a java class and received my 1st assignment. Its alot harder than i woulda thought and im kinda stuck and need abit of help.

    if im doing this right ive declared my variable and made them all user imputs but im confused on how to set up the calculations.help would be greatly appreciated, heres the criteria:

    also anything relating to area was me trying random things that didnt work.

    Write a program that computes the cost of painting and installing carpet in a room. Assume that the room has one door, two windows, and one book-shelf. Your program must do the following:
    a. Prompts the user to enter, in feet, the length, width, and height of a room. Read the dimensions of the room.
    b. Prompts the user to enter the widths and heights, in feet, of the door, each window, and the bookshelf. Read these quantities.
    c. Prompts the user to enter the cost, per square foot, of painting the walls. Read these quantities.
    d. Prompts the user to enter the cost, per square foot, of installing carpet. Read these quantities.
    e. Outputs the cost of painting the walls and installing the carpet.




    :import java.util.Scanner;
     
     
    public class Assignment1 {
     
    	public static void main(String[] args) {
     
    	Scanner in = new Scanner (System.in);
     
     
    	int Height;
    	int Width;
    	int Length;
    	int DLength;
    	int DWidth;
    	int W1Length;
    	int W1Width;
    	int W2Length;
    	int W2Width;
    	int BLength;
    	int BWidth;
    	int FloorCost;
    	int WallCost;
     
     
     
    System.out.println("ROOM Height");
    Height = in.nextInt();
    System.out.println("ROOM Width");
    Width = in.nextInt();
    System.out.println("ROOM Length");
    Length = in.nextInt();
    int Area = Length * Width;   //area of the floor
    int Tarea = Length * Width * Height * 4;  //area of the 4 walls
     
    System.out.println("DOOR Height");
    DLength = in.nextInt();
    System.out.println("DOOR Width");
    DWidth = in.nextInt();
    int Area1 = DLength * DWidth;    //area of the door
     
     
    System.out.println("WINDOW1 Height");
    W1Length = in.nextInt();
    System.out.println("WINDOW1 Width");
    W1Width = in.nextInt();
    int Area2 = W1Length * W1Width;  //area of the 1st window
     
    System.out.println("WINDOW2 Height");
    W2Length = in.nextInt();
    System.out.println("WINDOW2 Width");
    W2Width = in.nextInt();
    int Area3 = W2Length * W2Width;   //area of the 2nd window
     
    System.out.println("BOOKSHELF Height");
    BLength = in.nextInt();
    System.out.println("BOOKSHELF Width");
    BWidth = in.nextInt();
    int Area4 = BLength * BWidth;   //area of the bookshelf
     
    	System.out.println("FloorCost per sqaurefeet");
    	FloorCost = in.nextInt();
     
    	System.out.println("WallCost per sqaurefeet");
    	WallCost = in.nextInt();
     
     
    	int TotalAREA = Area1 + Area2 + Area3 + Area4;   //total area of everything minus the floor and walls
     
    	System.out.println("The Cost of Painting the walls" + (Tarea - TotalAREA) * WallCost);
    	System.out.println("The Cost of install carpet is " + Area * FloorCost);
     
     
     
    	}
    }


  2. #2
    Member
    Join Date
    Jun 2012
    Location
    Left Coast, USA
    Posts
    451
    My Mood
    Mellow
    Thanks
    1
    Thanked 97 Times in 88 Posts

    Default Re: beginner java program help

    Quote Originally Posted by Peeboelmeebo View Post
    ... how to set up the calculations....
    The flow for this program is strictly top-to-bottom. It cannot calculate area until it has the dimensions. It can't go back and plug in dimensional data into previous arithmetic expressions.

    Similarly, it can't calculate cost for floor covering until it knows the area of the floor and the price per square foot of carpet. It can't calculate the cost for wall covering until it knows the area that has to be covered and the price per square foot of wall covering.

    So, here's the deal:

    1. Prompt user for room dimensions and get length, width, height

    2. Calculate area of floor. (area = length*width)

    3. Calculate gross area of the four walls. I'll leave that up to you.

    4. Prompt user for door dimensions: dLength, dWidth.

    5. Calculate area of door.

    6. Prompt user for Window number 1 dimensions: w1Length, w1Height.

    7. Calculate area of Window number 1.

    8. Etc.


    See how it goes? First get dimensions from user. Then use them to calculate whatever...

    Anyhow...

    After all of the above calculations, you know the floor area. The wall area that has to be covered is equal to the gross area minus the area of the door minus the area of Window number 1, etc...

    Once you know the floor area and the wall area that has to be covered, use price information that you get from the user to calculate the cost of each.


    Cheers!

    Z

  3. The Following User Says Thank You to Zaphod_b For This Useful Post:

    Peeboelmeebo (February 13th, 2013)

  4. #3
    Member
    Join Date
    Feb 2013
    Location
    earth
    Posts
    88
    Thanks
    12
    Thanked 9 Times in 9 Posts

    Default Re: beginner java program help

    .

  5. The Following User Says Thank You to javaiscool For This Useful Post:

    Peeboelmeebo (February 13th, 2013)

  6. #4
    Junior Member
    Join Date
    Feb 2013
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: beginner java program help

    thank you both for the advice, i was able to successfully run the program with everything in the directions . Also can the if/then statement can be used on multiple things without having to retype it?

  7. #5
    Member
    Join Date
    Jun 2012
    Location
    Left Coast, USA
    Posts
    451
    My Mood
    Mellow
    Thanks
    1
    Thanked 97 Times in 88 Posts

    Default Re: beginner java program help

    Quote Originally Posted by Peeboelmeebo View Post
    ...can the if/then statement can be used on multiple things without having to retype it?
    Can you explain what you mean? Maybe give an example in pseudo-code or human language?

    Cheers!

    Z

  8. #6
    Junior Member
    Join Date
    Feb 2013
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: beginner java program help

    Quote Originally Posted by Zaphod_b View Post
    Can you explain what you mean? Maybe give an example in pseudo-code or human language?

    Cheers!

    Z

    The if-then and if-then-else Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)

    that explains it, and i suppose also answers my question.

Similar Threads

  1. Beginner,first java program assignment
    By geezlouise in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 31st, 2013, 08:36 PM
  2. Replies: 2
    Last Post: January 18th, 2013, 11:12 AM
  3. Java program (beginner) help?!
    By rk2010 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 10th, 2012, 01:30 PM
  4. Beginner Java Program Help/ txt database search
    By JavaConfused in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: September 21st, 2011, 10:20 AM
  5. [SOLVED] Java Beginner: Help with methods and returning values (hailstone program)
    By alf in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 14th, 2010, 07:28 PM