Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

/** Purpose: This program uses ReadData class toread data from a text file to in

ID: 3616916 • 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 all these examples work this is an example of a program that asks the user for the filethey want to use as input import java.util.*; import java.io.*; public class FileInOut {public static void main(String[] args)throwsFileNotFoundException {int count=0,i; String data,filename; Scanner in=new Scanner(System.in); System.out.println("Enter the name of your input file: "); filename=in.next(); Scanner input=new Scanner(new File(filename)); PrintStream output=new PrintStream(new File("output.txt")); while(input.hasNextLine())     {      data=input.nextLine();        output.println(data+"("+data.length()+")");    }   } } 2 examples of using a command line forinput     you would do it exactly like thisfirst and use the string as the file name public class commandinhello {    /**      * @param args the command linearguments      */     public static void main(String[] args) {    String message;    message=args[0];        System.out.println(message); // Display the string.     } } getting multiple items from the command line import java.io.*; import java.util.*; public class command { public static void main(String[] args) { int sum=0,i; double average; for(i=0;i