Question: A java question. Write an application IndexMaker which reads a simplified Java source file and produces an index containing identifiers . Print all the identifiers
A java question. 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. The file of reserved keywords is as follow. Download it and put in your project.
---------------------------------------------------------------------------
Here is a file of reserved keywords:
reserved.txt
abstract continue for new switch assert default goto package synchronized boolean do if private this break double implements protected throw byte else import public throws case enum instanceof return transient catch extends int short try char final interface static void class finally long strictfp volatile const float native super while
---------------------------------------------------------------------------
Print the identifiers in lexicographical order. Display the line numbers in numeric order.
We will assume:
1. every string consisting of only letters, numbers, and underscores is either an identifier or reserved keyword. But we are ignoring keywords
2. 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.
Use this line in your code for the file name
String filename = "ProcessRectangle.java"; //SUB "PaintJobCalculator.java"
Call the reserved keyword file reserved.txt
Please show the full code, Thank you!
-------------------------------------------------------------------------------------------------
Here are the Java files that are used: ProcessRectangle.java and PaintJobCalculator.java. CodeCheck will process both 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); } } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
