1

I apologize if my question is confusing, I'll try to explain it better here. I'm creating a Property Calculator where the user is required to enter the Rooms of the residence, the area of each room, and then the price. Which ultimately gets calculated (total area from each room * price).

I'm not too familiar with Java so I'm not sure why I'm unable to use the variable declared in the class, outside.

Here is the code, followed by the issue that is happening:

EDIT

    package realestatepropvalue;

import java.util.Scanner;
public class RealEstateProbValueA3
{
public static void main(String[] args) 
{
    Scanner sc = new Scanner ( System.in );        
    System.out.println ( "Hello friend, you will enter a series "
            + "of fields that'll calculate your Real Estate Property Value.");

    System.out.print ("Please enter a Street Number ");
    String streetnum = sc.next();
    sc.nextLine();
    System.out.println ("You entered the Street Number, " +streetnum );

    System.out.print ( "Please enter a Street Name ");
    String streetnam = sc.nextLine();
    System.out.println ("You entered the Street Name, " + streetnam +   " " );

END EDIT

    System.out.print ("Please enter the number of rooms! (Up to 5!) ");

    int roomcount = sc.nextInt();

    String[] places = new String[roomcount];
        for(int i = 0; i < places.length; i++) {
        places[i] = "Place Number: " + i;
        }

        sc.nextLine();

    System.out.println("You said that there were " + roomcount + " rooms!");

System.out.print ("Please enter the types of rooms (up to " +roomcount+ ") that fill up the " + roomcount + " rooms!\n"
            + "(Rooms like Living, Dining, Bedroom1-2, Kitchen, Bathroom, etc!) \n ") ;

   int squareCounter = 0;
    String[] types = new String[roomcount];
for(int i = 1; i < types.length; i++) {
    System.out.print ("Please enter the types of room " + places[i] + ": ");
    String roomName = sc.nextLine();
    types[i] = roomName;

    System.out.print ("Please enter the square feet of " + roomName + ": ");
    int squareFeet = sc.nextInt();

    squareCounter = squareFeet + squareCounter;

    System.out.println("Room name: " + roomName + " is: " + squareFeet + "square feet.");
    System.out.println("The counter total: " + squareCounter );

    System.out.println("What is the price per sq. feet?");
    int pricePer = sc.nextInt();

    int finalCalc = pricePer * squareCounter;
    System.out.println( "Estimated Property value: $____" + finalCalc);

}

Here is the log:

LOG EDIT

run:
Hello friend, you will enter a series of fields that'll calculate your Real 
Estate Property Value.
Please enter a Street Number 7
You entered the Street Number, 7
Please enter a Street Name Washington Street
You entered the Street Name, Washington Street 

END EDIT

Please enter the number of rooms! (Up to 5!) 3
You said that there were 3 rooms!
Please enter the types of rooms (up to 3) that fill up the 3 rooms!
(Rooms like Living, Dining, Bedroom1-2, Kitchen, Bathroom, etc!) 
Please enter the types of room Place Number: 1: Kitchen
Please enter the square feet of Kitchen: 50
Room name: Kitchen is: 50square feet.
The counter total: 50
What is the price per sq. feet?
50
Estimated Property value: $____2500
Please enter the types of room Place Number: 2: Please enter the square feet of : 

The last line immediately skips the type of room, and asks the square feet. Why does this happen?

Thank you for any help!

J Ben
  • 127
  • 9

0 Answers0