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

[Java] URGENT! Please check your code at the link I provide before you submit yo

ID: 3836768 • Letter: #

Question

[Java] URGENT! Please check your code at the link I provide before you submit your code here.

Here's the link: http://www.codecheck.it/files/170405164364q7baywqni9maqzcfwf57iex
Write an application IndexMaker which reads a simplified Java source file and produces an index containing identifiers . Print all the identifiers and all the line numbers on which each identifier occurs. But do not print reserved keywords. When you find an identifier, compare it against a list of reserved keywords and skip keywords. Be smart about this and do not use 50 if statements. Put the keywords in a data structure and check each identifier to see if it is in the collection. Here is a file of reserved keywords. Download it and put in your project.
Print the identifiers in lexicographical order. Display the line numbers in numeric order.
We will assume
every string consisting of only letters, numbers, and underscores is either an identifier or reserved keyword. But we are ignoring keywords
there are no comments to confuse things
You will need to set the delimiter: ...useDelimiter("[^A-Za-z_]+"); For simplicity, there will not be any identifiers that contain numbers.
Your output should be in this format:
ProcessRectangle: [4]
Rectangle: [2, 9, 11]
String: [7]
System: [13, 16]
args: [7]
You can simply declare that the main method throws the FileNotFoundException. You do not need to catch it.
Updated 5/3/2017
Use this line in your code for the file name
String filename = "ProcessRectangle.java"; //SUB "PaintJobCalculator.java"
Call the reserved keyword file reserved.txt
Here are the Java files that are used: ProcessRectangle.java and PaintJobCalculator.java. CodeCheck will process both files.
import java.awt.Rectangle;

public class ProcessRectangle
{

public static void main(String[] args)
{
Rectangle rec;

rec = new Rectangle(100, 200, 80, 50);
rec.translate(20, 25);
System.out.println(rec.getX() + ", " + rec.getY() );
rec.grow(10,0);

System.out.println(rec);

}

}
public class PaintJobCalculator
{
private double radius;
private double height;

public static final int SQ_FT_PER_SQ_YARD = 9;
public static final double COST_PER_GALLON_OF_PAINT = 95.5;
public static final double SQUARE_FEET_PER_GALLON = 40;
public static final double LABOR_COST_PER_SQUARE_YARD = 100.0;

public PaintJobCalculator(double theHeight, double theRadius)
{
height = theHeight;
radius = theRadius;
}

public double getSurfaceArea()
{
double cylinderSurfaceArea = 2 * Math.PI * radius * height;
double domeSurfaceArea = 2 * Math.PI * radius * radius;
return cylinderSurfaceArea + domeSurfaceArea;
}

public double getPaintCost()
{
double paintCost = getSurfaceArea()
/ SQUARE_FEET_PER_GALLON * COST_PER_GALLON_OF_PAINT;
return paintCost;
}

public double getLaborCharge()
{
double squareYards = getSurfaceArea() / SQ_FT_PER_SQ_YARD;
return squareYards * LABOR_COST_PER_SQUARE_YARD;
}

public double getCustomerPrice()
{
return getPaintCost() + getLaborCharge();
}
public void setHeight(double theHeight)
{
height = theHeight;
}

public void setRadius(double theRadius)
{
radius = theRadius;
}

}
Use the following files:
PaintJobCalculator.java
public class PaintJobCalculator
{
private double radius;
private double height;

public static final int SQ_FT_PER_SQ_YARD = 9;
public static final double COST_PER_GALLON_OF_PAINT = 95.5;
public static final double SQUARE_FEET_PER_GALLON = 40;
public static final double LABOR_COST_PER_SQUARE_YARD = 100.0;

public PaintJobCalculator(double theHeight, double theRadius)
{
height = theHeight;
radius = theRadius;
}

public double getSurfaceArea()
{
double cylinderSurfaceArea = 2 * Math.PI * radius * height;
double domeSurfaceArea = 2 * Math.PI * radius * radius;
return cylinderSurfaceArea + domeSurfaceArea;
}

public double getPaintCost()
{
double paintCost = getSurfaceArea()
/ SQUARE_FEET_PER_GALLON * COST_PER_GALLON_OF_PAINT;
return paintCost;
}

public double getLaborCharge()
{
double squareYards = getSurfaceArea() / SQ_FT_PER_SQ_YARD;
return squareYards * LABOR_COST_PER_SQUARE_YARD;
}

public double getCustomerPrice()
{
return getPaintCost() + getLaborCharge();
}
public void setHeight(double theHeight)
{
height = theHeight;
}

public void setRadius(double theRadius)
{
radius = theRadius;
}

}
ProcessRectangle.java
import java.awt.Rectangle;

public class ProcessRectangle
{

public static void main(String[] args)
{
Rectangle rec;

rec = new Rectangle(100, 200, 80, 50);
rec.translate(20, 25);
System.out.println(rec.getX() + ", " + rec.getY() );
rec.grow(10,0);

System.out.println(rec);

}

}

Explanation / Answer

PROGRAM:

import java.io.BufferedReader;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

import java.util.ArrayList;

import java.util.List;

import java.util.TreeMap;

public class IndexMaker {

public static String KEYWORDFILENAME="";// provide your keywords file path

public static String JAVAFILEPATH=""; //provide your java filepath

public static void main(String[ ] args) throws

FileNotFoundException,IOException {

BufferedReader bufferedReader=null;

BufferedReader filebufferedReader=null;

String currentLine="";

int lineNo=0;

List<String>keyWordsList=new ArrayList();

TreeMap<String,String>identifierIndexes=new TreeMap<String,String>(); /* As treeMap is sorted,here we use treeMap for lexicographical order

*/

bufferedReader=new BufferedReader(new FileReader(KEYWORDFILENAME));

filebufferedreader=new BufferedReader(new FileReader(JAVAFILEPATH));

while ((currentLine=bufferedReader.readLine()) !=null)

{

keyWordsList.add(currentLine);

}

while(currentLine=filebufferedReader.readLine()) !=null)

{

lineNo++;

String[ ] split=currentLine.split("[^A-Za-z_]+");

for(int i=0;i<split.length;i++)

{

if(!"".equalsIgnoreCase(split[i]) && !keWordsList.contains(split[i]))

{

if(identifierIndexes.containsKey(split[i]))

{

identifierIndexes.put(split[i],identifierIndexes.get(split[i]) + lineNo + ",");

}

else

{

identifierIndexes.put(split[i],lineNo + ",");

}

}

}

}

identifierIndexes.keySet().stream().forEach((String name) ->{ // lamda expressions for iterating treeMap

String identifier=name;

String temp=identifierIndexes.get(name);

String occurrences="[" + temp.substring(0,temp.lastIndexOf(",")) + "]";

System.out.println(identifier + " : " + occurrences);

});

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote