java program Word : SYZYG# Scrabble score is: 1 + 4 + 10 + 4 + 2 + 0-21 Name the
ID: 3671012 • Letter: J
Question
java program
Word : SYZYG# Scrabble score is: 1 + 4 + 10 + 4 + 2 + 0-21 Name the program: ModifiedScrabbleScorexx.java, where XX are your initials. 3. In the workplace of computer programmers, a coder's ability is measured in the lines of code he generates in a certain amount of time. To do so, you need to measure the Source Lines of Code (SLOC) that each programmer generates. All the code written at a particular company is in C++, and the programmers use block commenting schemes, thus there are no lines containing both a code and a comment. In C++, a comment line begins with a double forward slash (/). Thus, in all the code to evaluate, there will be three kinds of lines: Empty line, which will only contain whitespace characters. Whitespace characters are the space and tab characters. Lines with a comment . (Any line that begins with a "//". There must be two slashes without white space between them.) o Lines with C++ code (Any line that contains non-whitespace and does not contain a comment) Code lines or comment lines may also contain whitespace (tabs and spaces) before the code or comment begins. o o Write a SLOC counter for C++ code. The Java program should prompt the user for the number of lines of code and then read in this value, and read in as many lines from the user via the keyboard. Lastly, the program must report the total number of lines inputted, the number of empty lines, the number of comment lines, and the number of code lines. Lines of text in the program will be no longer than 75 characters. Output should look similar to below Sample Runs How many lines of code? 6 // This function generates general gibberish int chicken (int i )I coutExplanation / Answer
/**The java proram ModifiedScrabbleScoreXX that prompts
* user to enter number of lines of code to enter.
* Then read lines from the console .
* Then find the code lines, comment lines and empty
* lines. Then print the number of lines, code
* lines, comment lines and empty lines to console*/
//ModifiedScrabbleScoreXX.java
import java.util.Scanner;
public class ModifiedScrabbleScoreXX
{
public static void main(String[] args)
{
//Create an instance of Scanner class
Scanner scanner=new Scanner(System.in);
//Initialize the variables to zero
int numLines=0;
int codeLines=0;
int emptyLines=0;
int commentLines=0;
System.out.print("How many lines of code ?");
//read number of lines
numLines=Integer.parseInt(scanner.nextLine());
String[] lines=new String[numLines];
//read lines from console
for (int i = 0; i < lines.length; i++)
lines[i]=scanner.nextLine();
//run for loop that finds the comment lines,
//empty lines and codeLines
for (int i = 0; i < lines.length; i++)
{
//trime the lines if white spaces
String line=lines[i].trim();
if(line.startsWith("//"))
//incremnt the commentLInes by one
commentLines++;
else if(line.equals(""))
//increment the empty lines by one
emptyLines++;
else
//increment the code linesby one
codeLines++;
}
System.out.println("The code contains "+numLines
+" total lines(s)");
System.out.println("The code contains "+codeLines
+" code lines(s)");
System.out.println("The code contains "+emptyLines
+" empty lines(s)");
System.out.println("The code contains "+commentLines
+" comment lines(s)");
}
}
---------------------------------------------------------------------------------------------------------
Sample Output::
How many lines of code ?6
//This function generates general ginnerish
int chicken(int i){
cout<<"Nuclear Chicken:"<<i<<" dies. ";
return (i/6);
}
The code contains 6 total lines(s)
The code contains 4 code lines(s)
The code contains 1 empty lines(s)
The code contains 1 comment lines(s)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.