Your task is to declare the necessary variables and implement the method bodies
ID: 3724569 • Letter: Y
Question
Your task is to declare the necessary variables and implement the method bodies according to the comments in the code and in this document so the program functions as described. Start with the variable declarations, then implement the constructor code.
https://gyazo.com/6979db470df58890a5fb311a9186135f
https://gyazo.com/db0100391bf9356d41ae449f4aeaab70
https://gyazo.com/1e144c111ec831d2a81a6f9a1cffccd6
https://gyazo.com/b18d885febd79ed72219d64699af50f4
https://gyazo.com/ae599dbb599c786f8cc8b2f9320d4ca7
https://gyazo.com/4347b10894c2e537e7e33cd9814efa3b
https://gyazo.com/db14fcfc731f2cabf804443f11cbba35
I tried this already, it doesn't work:
import java.util.*;
import java.lang.String;
import java.lang.Character;
public class LetterCounter{
Scanner reader = new Scanner(System.in);
int lettercount, linecount;
String line;
char ch,ch1;
boolean _case=true;
boolean caseSensitive;
LetterCounter(){
lettercount=0;
linecount=0;
ch=Character.MIN_VALUE;
}
public void processLine(String line){
System.out.print("Please input the letter to be counted: ");
String userCharStr = reader.nextLine();
System.out.print("Do you want the count to be case sensitive? <enter 1 for yes, 0 for no> ");
int _case = reader.nextInt();
if(_case==1)
caseSensitive=true;
else if(_case==0)
caseSensitive=false;
setUserLetter(userCharStr,caseSensitive);
int Length = line.length();
ch1=Character.toUpperCase(ch);
for (int i =0;i<Length;i++){
if(_case == 0)
{if(line.charAt(i)==ch || line.charAt(i)==ch1)
lettercount++;
if(line.charAt(i)=='.')
linecount++;}
else if(_case == 1)
{if(line.charAt(i)==ch)
lettercount++;
if(line.charAt(i)=='.')
linecount++;
}
}
}
public void setUserLetter(String userCharStr, boolean caseSensitive ){
ch = userCharStr.charAt(0);
_case=caseSensitive;
}
public int getLetterCount(){
return lettercount;
}
public char getUseLetter(){
return ch;
}
public int getLineCount(){
return linecount;
}
Using jgrasp/java, the above answer doesn't even compile
Explanation / Answer
You just need to put one "}" in the last then it will successfully compiled.
/*******************************LetterCounter*****************************/
import java.util.*;
import java.lang.String;
import java.lang.Character;
public class LetterCounter {
Scanner reader = new Scanner(System.in);
int lettercount, linecount;
String line;
char ch, ch1;
boolean _case = true;
boolean caseSensitive;
LetterCounter() {
lettercount = 0;
linecount = 0;
ch = Character.MIN_VALUE;
}
public void processLine(String line) {
System.out.print("Please input the letter to be counted: ");
String userCharStr = reader.nextLine();
System.out.print("Do you want the count to be case sensitive? <enter 1 for yes, 0 for no> ");
int _case = reader.nextInt();
if (_case == 1)
caseSensitive = true;
else if (_case == 0)
caseSensitive = false;
setUserLetter(userCharStr, caseSensitive);
int Length = line.length();
ch1 = Character.toUpperCase(ch);
for (int i = 0; i < Length; i++) {
if (_case == 0)
{
if (line.charAt(i) == ch || line.charAt(i) == ch1)
lettercount++;
if (line.charAt(i) == '.')
linecount++;
}
else if (_case == 1)
{
if (line.charAt(i) == ch)
lettercount++;
if (line.charAt(i) == '.')
linecount++;
}
}
}
public void setUserLetter(String userCharStr, boolean caseSensitive) {
ch = userCharStr.charAt(0);
_case = caseSensitive;
}
public int getLetterCount() {
return lettercount;
}
public char getUseLetter() {
return ch;
}
public int getLineCount() {
return linecount;
}
}
if you have more probelm in the code then upload the code please, It is not possible to write the code again ...
or give the url of your code not in snapshots.....
Thanks, Please let me know if you have problem...
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.