I need a flow chart for this code below. import java.io.*; import java.lang.*; i
ID: 3813992 • Letter: I
Question
I need a flow chart for this code below.
import java.io.*;
import java.lang.*;
import java.util.*;
public class Week11HW
{
public static int checkOccurrences(String fileLine,String charc)
{
int kk=0;
int lasId=0;
while(lasId != -1)
{
lasId = fileLine.indexOf(charc,lasId);
if(lasId != -1)
{
kk ++;
lasId += charc.length();
}
}
return kk;
}
public static String getFileName(Scanner sann)
{
String fileName;
File ff;
while(true)
{
System.out.println("Please enter the name of the file you want to search from in the directory:");
fileName=sann.nextLine();
ff=new File(fileName);
if(!ff.exists())
{
System.out.println("**Error - I'm sorry, the file "+fileName+" does not exist in that directory. Please try again.");
}
else
break;
}
return fileName;
}
public static void displayFileContent(String[] fileLines,int fileLineCnt)
{
for(int kk=0;kk<fileLineCnt;kk++)
{
System.out.println((kk+1)+" "+fileLines[kk]);
}
}
public static void main(String[] args)throws Exception
{
System.out.println("Welcome to the file searcher program!");
System.out.println("We will be working in the directory"{ENTER_YOUR_DIRECTORY_WHERE_FILE_IS_HERE IN MAC OR PC FORMAT}"");
Scanner sann=new Scanner(System.in);
while(true)
{
String fileName;
String[] fileLines=new String[100];
String fileLine;
String charc="";
int fileLineCnt=0;
int wordOccurCnt=0;
int tt=0;
File ff;
fileName =getFileName(sann);
ff=new File(fileName);
BufferedReader bff=new BufferedReader(new FileReader(ff));
while((fileLine=bff.readLine())!=null)
{
fileLines[fileLineCnt]=fileLine;
fileLineCnt++;
}
bff.close();
System.out.println("OK...Found "+fileName+" - That file looks like this: ");
displayFileContent(fileLines,fileLineCnt);
System.out.println("What character or characters do you want to search for in the file:");
charc=sann.nextLine();
for(int kk=0;kk<fileLineCnt;kk++)
{
int tpp = checkOccurrences(fileLines[kk],charc);
wordOccurCnt += tpp;
if(tpp!=0)
{
tt=tt+1;
if(tt==1)
{
System.out.println("Found "+charc+":");
}
System.out.println((kk+1)+" "+fileLines[kk]);
}
}
if(tt==0)
System.out.println(charc+" was not found in the file.");
else
System.out.println(charc+ " was found in "+tt+" lines and appeared "+wordOccurCnt+" times.");
System.out.println("Play Again (Yes/No)?:");
String tpp = sann.nextLine();
if(tpp.equalsIgnoreCase("No"))
break;
}
}
}
Explanation / Answer
#include <iostream>
002
#include <Windows.h>
003
using namespace std;
004
005
struct Player
006
013
};
014
015
struct Ghost
016
024
};
025
026
const char SYMBOL_EMPTY = ' ';
027
const char SYMBOL_PLAYER = '@';
028
const char SYMBOL_GHOST = 'G';
029
const char SYMBOL_WALL = '#';
030
const int MapDx = 10;
031
const int MapDy = 20;
032
const int GameSpeed = 100;
033
const int LEFT = 1;
034
const int RIGHT = 2;
035
const int UP = 3;
036
const int DOWN = 4;
037
int direction = RIGHT;
038
039
char map[10][20] =
040
come (x >= zero && x < MapDx && y >= zero && y < MapDy);
055
}
056
057
bool movePlayer(Player &player, int x, int y)
058
come false;
062
}
063
064
char ch = map[x][y];
065
066
if(ch != SYMBOL_EMPTY)
067
come false;
069
}
070
071
if (isValidPos(player.x, player.y))
072
075
player.x = x; player.y = y;
076
map[player.x][player.y] = SYMBOL_PLAYER;
077
come true;
078
}
079
080
bool moveGhost(Ghost &ghost, int x, int y)
081
{
082
if (!isValidPos(x, y))
083
{
084
come false;
085
}
086
087
char ch = map[x][y];
088
089
if (ch != SYMBOL_EMPTY)
090
{
091
come false;
092
}
093
094
if (isValidPos(ghost.x, ghost.y))
095
098
ghost.x = x; ghost.y = y;
099
map[ghost.x][ghost.y] = SYMBOL_GHOST;
100
come true;
101
}
102
103
void GhostAI(Ghost &ghost, Player &player)
104
114
115
void showMap()
116
121
}
122
123
void showPlayer(Player &player)
124
whereas (true)
138
150
else if (GetAsyncKeyState(VK_LEFT))
151
154
else if (GetAsyncKeyState(VK_RIGHT))
155
158
switch (direction)
159
173
for (int ghost = 0; ghost < 3; ghost++)
174
191
}
192
Sleep(GameSpeed);
193
}
194
}
195
196
197
int main()
198
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.