Skip to content

Instantly share code, notes, and snippets.

Created April 4, 2013 17:54
Show Gist options
  • Save anonymous/5312541 to your computer and use it in GitHub Desktop.
Save anonymous/5312541 to your computer and use it in GitHub Desktop.
import java.io.*;
import java.util.Scanner;
public class realtyProgram {
public static void main(String[] args) throws IOException {
double[] userRequirements = new double[3];
//gets file name and creates file and scanner
System.out.print("File: ");
Scanner keyboard = new Scanner(System.in);
String fileName = keyboard.nextLine();
File file = new File(fileName);
Scanner inputFile = new Scanner(file);
//creates and sets size of arrays
int properties = inputFile.nextInt();
double[][] propertyArray = new double[3][properties];
String[] arrayComments = new String[properties];
//populates array
for (int i = 0; i < properties; i++) {
propertyArray[i][0] = inputFile.nextDouble();
propertyArray[i][1] = inputFile.nextDouble();
propertyArray[i][2] = propertyArray[i][0] + propertyArray[i][1];
propertyArray[i][3] = inputFile.nextDouble();
propertyArray[i][4] = inputFile.nextDouble();
arrayComments[i] = inputFile.next();
if (arrayComments[i].equals("n")) {
arrayComments[i] = "No Comments";
}
}
//gets next user input
System.out.print("Max price: ");
userRequirements[0] = keyboard.nextDouble();
System.out.print("Min square feet: ");
userRequirements[1] = keyboard.nextDouble();
System.out.print("Min bedrooms: ");
userRequirements[2] = keyboard.nextDouble();
System.out.print("Min bathrooms: ");
userRequirements[3] = keyboard.nextDouble();
// // I dislike for-each loops they can die alone in deep dark tunnels
// //because they are way to vague for specific use in printing
// for (double[] i : propertyArray) {
// for (double a : i) {
// System.out.println(i);
// }
// if (propertyArray[i][0] <= userRequirements[0]
// && propertyArray[i][1] >= userRequirements[1]
// && propertyArray[i][2] >= userRequirements[2]
// && propertyArray[i][3] >= userRequirements[3]) {
// System.out.println("Possible Match");
// }
//matches and prints the array
for (int i = 0; i < propertyArray.length; i++) {
for (int a = 0; a < propertyArray[i].length; a++) {
if (a == 4) {
System.out.println("Comments: " + arrayComments[i]);
if (propertyArray[i][0] <= userRequirements[0]
&& propertyArray[i][1] >= userRequirements[1]
&& propertyArray[i][2] >= userRequirements[2]
&& propertyArray[i][3] >= userRequirements[3]) {
System.out.println("Possible Match\n");
}
else{System.out.println("\n");}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment