/* Purpose: This program uses ReadData class toread data from a text file to ini
ID: 3616902 • Letter: #
Question
/* Purpose: This program uses ReadData class toread data from a text file to initialize
* the number of apartments, employees, carports,garages, etc.
* It also initializes the objects for theApartment class based on the input
* from the data file
*/
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Proj2Read implementsproj2Constants
{
private static Scanner input;
/**
* @param args
*
*/
public static void main(String[] args)
{
int lineCounter = 0;
String aptComplexName;
int maxNumApartments;
int maxNumEmployees;
int maxNumCarports;
int maxNumGarages;
int numAptDetails;
if (args.length < 1){
System.err.println("usage: java classname(e.g.,TestAptComple)" +
" <file name in the same dir>");
System.exit(ABNORMAL_EXIT);
}
try{
input = new Scanner(newFile(args[ZEROI]));
}
catch(FileNotFoundException FNFE){
System.err.printf("Could not find the input file%s ", args[ZEROI]);
System.exit(ABNORMAL_EXIT);
}
aptComplexName = input.nextLine(); //reading aline
System.out.println(aptComplexName);
//call method of AptCmplex to assign thename
maxNumApartments = input.nextInt();
maxNumEmployees = input.nextInt();
maxNumCarports = input.nextInt();
maxNumGarages = input.nextInt(); // reading 4values in 1 line
System.out.printf("%s, %d, %d, %d, %d ",
aptComplexName, maxNumApartments,maxNumEmployees, maxNumCarports, maxNumGarages);
// call approriate methods to set the above in teAptComplex class
String comment = input.nextLine(); // to go tonext line in input
int i = 1;
while ((i <= maxNumApartments) &&input.hasNext()){
int aptNumber;
int aptArea;
int aptBedrooms;
double aptBathrooms;
boolean aptPatio;
double monthly_rent;
aptNumber = input.nextInt();
aptArea = input.nextInt();
aptBedrooms = input.nextInt();
aptBathrooms = input.nextDouble();
aptPatio = input.nextBoolean();
monthly_rent = input.nextDouble(); // read allapt fields from one line
comment = input.nextLine();
// call apartment constructor to create anobject
System.out.printf("%d, %d, %d, %f, %b,%f ",
aptNumber, aptArea, aptBedrooms, aptBathrooms,aptPatio, monthly_rent);
i += 1;
}
maxNumApartments = i-1; // will take care even ifthe input ends earlier
}
}
public interfaceproj2Constants
{
int ABNORMAL_EXIT =1;
int BASE_INDEX =0;
String DEFAULT_APT_COMPLEX_NAME ="Maverick Apartments";
int DEFAULT_APT_NUMBER =0;
int DEFAULT_CPORT_NUMBER =0;
int DEFAULT_GARAGE_NUMBER =0;
String DEFAULT_FIRST_NAME ="John";
String DEFAULT_LAST_NAME ="Doe";
int DEFAULT_LEASE_PERIOD = 11;//in months
int DEFAULT_ID =999;
double DEFAULT_SALARY =1500.00;
double MAX_SALARY =10000.00;
int MAX_APARTMENTS =5;
int MAX_TENANTS =5;
double ZEROD =0.000;
int ZEROI = 0;
}
Explanation / Answer
please rate - thanks it appears this program reads the data from a file, where the nameof the file is input through the argument list. try this java Proj2Read argument list where the argument list is the name of the input file. so ifthe name of the input file is input.txt it would be java Proj2Read input.txt
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.