ICSI 201 week3 homework

This is a java homework. Please follow all instruction and requirement in the text file. This is introduction to computer science and all the class and method is listed in the top of text. Please follow this text and no need to use h igher level method.

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

Homework 3
Read the first chapters 5 to 7
—————–Objectives:
array and functions
numberical arrays
character arrays
Text File, File operations,
Exception
Built-in class
User defined class
class vs. objects
class members
instance members
——————Problem 1 (25 points)
Implement static statistics functions.
Create a class that is equipped with the following static functions, which will be
called in main function.
popluatearray function populates an array input with random values between an lower
bound and upper bound.
calmean function that calculates mean of the input array and return the mean.
showdifference displays the difference between each data with respect to the mean
calvariance calculates the variance of the array.
calstandarddeviation calculates the standard deviation of the array.
Please notice that in my following sample code, I provided two overloading
functions for calvariance and showdifference, respectively,
showing that you can call calmean function either outside or inside in those
functions. You can implement both and test both, or just implement one and test
that one only, as long as your code can compile and work.
https://www.mathsisfun.com/data/standard-deviation.html
A main function interacts with user for getting input of an array size and
subsequently an array of double values of that size, then call the aforementioned
functions to obtain average, variance and standard deviations for the dataset.
A sample run of the program should look like the following on screen (the data is
approximated here, should be more accurate up to the second position after the
decimal though.
Please provide size of the array: 5
Please provide the five values: 600 470 170 430 300
The mean is 394
The difference from each number to mean: 206, 76 -224 36 -94
The variance is 21704
The Standard Deviation is 147
public class statistics
{
static void populatearray(double[] data)
{
}
static double calmean(double[] data)
{
}
static void showdifference(double [] data, double mean)
{
}
static void showdifference(double [] data)
function inside on the fly
{
// you can also call mean
}
static double calVariance(double [] data, double mean)
{
}
static double calVariance(double [] data)
inside on the fly
{
// you can also call mean function
}
static double calsd(double variance)
{
}
static void display( double[] data)
{
}
public static void main(String [] args)
{
//call the above functions in proper order and using proper input.
}
}
Problem 2 (25 points)
Counting Character Frequency.
Write a program to analyze a text file (a novel or a report, or just a sequence of
letters or symbols),
by reading the file into a byte array, convert to a string, and then scan the
string letter by letter to count the frequencies of all unique characters in the
text, after that, the letters with frequencies greater than 0 and the frequencies
are reported side by side.
All members of the class can be static.
For example if the text file test1.txt contains AAACMJKYYKNa1C
Your output should look like
Ascii code: the char: frequency
49: 1: 1
65: A: 3
67: C: 2
74: J: 1
75: K: 2
77: M: 1
78: N: 1
89: Y: 2
97: a: 1
Problem 3: 25 points
A complex number is composed of two parts – a real part and an imaginary part which can be represented as two single or two double precision fields. This
suggests defining a new class type.
Write a program to support basic complex number arithematic operations.
Please design your own complex class (this is a requirement) that consists of four
functions to implement add, substract, multiplication and divide functions on
complex numbers. Notice that I might have provided multiplication and conjugate
operations in class discussion.
Your project should consists of two classes, one is the testclass, the other one is
called mycomplex. For the mycomplex,
make all memebers non-static, yes all members should be instance members because we
need to use multiple instances created from the same class.
A sample running of the your program should look like the following:
Please input the first complex number’s real part: 2
Please input the first complex number’s imaginary part: 4
Please input the second complex number’s real part:3
Please input the second complex number’s imaginary part:5
Your first number is 2+4i.
your second number is 3+5i.
The multiplication of your two complex number is: -14+22i.
The summation of your two complex number is 5+9i.
The subtraction result is -1-1i.
The result of division is … (the result should be displayed here)
Do you need to calculate summation and subtraction for another pair of complex
numbers?
N
Thank you, exiting!
Hint:
You can find the definition of complex number at
http://mathworld.wolfram.com/ComplexNumber.html and
http://www.uncwil.edu/courses/mat111hb/Izs/complex/complex.html.
Problem 4 (2-D array and class/objects)
25 points
You need to adapt the TicTacToe Framework to a connect4 random player agent to
allow a computer to play against humanbeing player by picking a random legitimate
move.
Your program should support the following features. 1. Allow human player to pick
who go first. 2. Detect who win. 3. To pick a random legitmate move to play agains
the human being player. 4.reject illegal move made by human being player.
Deliverables:
80% Source code, with appropriate comments
10% Running/test results: screenshots or/and result text file. Representative test
cases should be considered whenever appropriate.
10% Documentation: A short description about your solution and what new programming
elements, or rules, constructs you have used in the homework.
If your solutions do not produce what is expected, please also document where the
problem is and your observation.
How to capture the output of your program?
Out of many methods, here are two simple ones. (TA could help)
Method 1: Set breakpoint at the closing of your source code, then click debug>start to run your program. When the black DOS window has all your output data,
right click the title bar of the DOS window, then select menu, then highlight the
output which you want to copy, then right click the title again, then switch to a
text editor such as TextPad, then past the output to the Textpad, then save the
output file to disk. Print the file out as your output.
Method 2: If the output is going to be NOT longer than one screenful, you can
simply press the printscreen key (a function key on your keywboard ) to capture the
current screen to a buffer which you cannot see, and then open a blank word
document, then, press ctrl-v, you will see that the captured screen will be pasted
into your word document. You can add a brief description of the test result and
then save the word document to a file. Of course, from word, you can easily print
out the document.
package mytictactoe;
public class testmyttt {
public static void main(String[] args) {
// TODO Auto-generated method stub
myttt.initializegame();
myttt.displaygame();
myttt.play();
}
}
package myttt;
public class move {
int row;
int col;
move(int row, int col)
{
this.row=row;
this.col=col;
}
move()
{
}
@Override
public boolean equals(Object righthand)
{
return (row==((move)righthand).row&&col==((move)righthand).col);
}
}
package myttt;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
public class myttt {
static
static
static
static
static
static
char [][] board;
final char EMPTY=’-‘;
final char FPLAYER=’X’;
final char SPLAYER=’O’;
Scanner keyboard;
int step;
static ArrayList allpossiblemoves=new ArrayList();
static void makeamove(move mv)
{
if (step%2==0)
else
board[mv.row][mv.col]=FPLAYER;
board[mv.row][mv.col]=SPLAYER;
step++;
allpossiblemoves.remove(mv);
}
static boolean isgameover(move mv)
{
boolean flag=false;
// update flag
return flag;
}
static boolean isgameover()
{
boolean flag=false;
// update flag
//check each row
for(int row=0; row

Still stressed from student homework?
Get quality assistance from academic writers!

Order your essay today and save 25% with the discount code LAVENDER