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

package testagain; import java.util.Scanner; import java.io.*; /** * * @author *

ID: 3617375 • Letter: P

Question

package testagain;
import java.util.Scanner;
import java.io.*;
/**
*
* @author
*/
public class Main implements projConstants
{

    private static Scanner ins = new Scanner(System.in);
    private static int index;
    private static Scanner input;

    /**
     * @param args the command linearguments
     */
    public static void main(String[] args)
    {

        Stringfilename;
        int numComplexes;
       String complexName;
       int numApartments;
       int numCarports;
       int numGarages;
       double carportRent;
       double garageRent;
       int numEmployees;
       int numTenants;
       String inputLine;

       System.out.println("Enter the name of the input file: ");
        filename =ins.next();
        //Scanner input =null;
        try
        {
           input = new Scanner(new File(filename));
        }
       catch(FileNotFoundException FNFE)
        {

         System.err.printf("Could not find the input file %s ",filename);
         System.exit(ABNORMAL_EXIT);
        }

        inputLine = input.nextLine();

        while(inputLine.charAt(BASE_INDEX) == '/') inputLine =input.nextLine();

    numComplexes = Integer.parseInt(inputLine);

    inputLine = input.nextLine();
        while(inputLine.charAt(BASE_INDEX) == '/') inputLine =input.nextLine();
        complexName =inputLine;


        System.out.printf("%d %s ",
   numComplexes, complexName);
    }

Explanation / Answer

please rate - thanks with nextLine you're leaving the ' ' in the input buffer sothey are being read as a null string. read the //, then read the next part of the comment separately andit works when not a comment must then concatenate the next part of theinput. (not sure if this is how to do it-but it works import java.util.Scanner; import java.io.*; /** * * @author */ public class Main implements projConstants {      private static Scanner ins = newScanner(System.in);     private static int index;     private static Scanner input;     /**      * @param args the command linearguments      */     public static void main(String[] args)     {         String filename;         int numComplexes;        String complexName;        int numApartments;        int numCarports;        int numGarages;        double carportRent;        double garageRent;        int numEmployees;        int numTenants;        String inputLine;        System.out.println("Enter the name of the input file: ");         filename =ins.next();         //Scanner input =null;         try         {            input = new Scanner(new File(filename));         }        catch(FileNotFoundException FNFE)         {          System.err.printf("Could not find the input file %s ",filename);          System.exit(ABNORMAL_EXIT);         }          inputLine =input.next();         while(inputLine.charAt(BASE_INDEX) == '/')           { inputLine= input.nextLine();            inputLine = input.next();           }      inputLine=inputLine+input.nextLine();      numComplexes =Integer.parseInt(inputLine);      inputLine = input.next();         while(inputLine.charAt(BASE_INDEX) == '/')           { inputLine= input.nextLine();            inputLine = input.next();           }         inputLine=inputLine+input.nextLine();         complexName =inputLine;         System.out.printf("%d %s ",    numComplexes, complexName);     } } interface projConstants {     int    ABNORMAL_EXIT                 = 1;     int    BASE_INDEX                    = 0;     String DEFAULT_APT_COMPLEX_NAME       ="undefined"; }