need help with code I wrote. This code is a maze gui, and i need help with the method
shorterstpath(); here is my code:
******mazeApp*******
package mazepackage;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.TextInputDialog;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class MazeApp extends Application
{
// default canvas size is DEFAULT_SIZE-by-DEFAULT_SIZE
private static final int DEFAULT_SIZE = 768;
private int width = DEFAULT_SIZE;
private int height = DEFAULT_SIZE;
// The graphics context is needed to enable drawing on the canvas
private GraphicsContext gc;
// boundary of drawing canvas, 0% border
// private static final double BORDER = 0.05;
private static final double BORDER = 0.00;
private double xmin, ymin, xmax, ymax;
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage primaryStage)
{
Group root = new Group();
Canvas canvas = new Canvas(width, height);
gc = canvas.getGraphicsContext2D();
gc.setLineWidth(2);
gc.setFill(Color.WHITE);
gc.fillRect(0, 0, width, height);
root.getChildren().add(canvas);
TextInputDialog tid = new TextInputDialog();
tid.setTitle(\"Maze Size\");
tid.setHeaderText(\"Enter maze size between 10 and 50\");
tid.showAndWait();
int size = Integer.parseInt(tid.getResult());
if (size > 50)
size = 50;
if (size < 10)
size = 10;
primaryStage.setTitle(\"Maze Application\");
primaryStage.setScene(new Scene(root));
primaryStage.setResizable(false);
// Make sure that the application goes away when then window is closed
primaryStage.setOnCloseRequest(e -> System.exit(0));
primaryStage.show();
Maze maze = new Maze(this, size);
// Must solve the maze in a separate thread or else
// the GUI wont update until the end.....
Thread solver = new Thread(
new Runnable () {
public void run()
{
while(true)
{
maze.buildAndDrawMaze();
maze.findShortestPath();
try
{
Thread.sleep(5000);
}
catch(Exception e) { }
gc.setFill(Color.WHITE);
gc.fillRect(0, 0, width, height);
}
}
});
solver.start();
}
/**
* Sets the pen color to the specified color.
*
* @param color the color to make the pen
*/
public void setPenColor(Color color) {
gc.setStroke(color);
}
/**
* Sets the pen color to the specified color.
*
* @param color the color to make the pen
*/
public void setFillColor(Color color) {
gc.setFill(color);
}
/**
* Sets the x-scale to the specified range.
*
* @param min the minimum value of the x-scale
* @param max the maximum value of the x-scale
* @throws IllegalArgumentException if {@code (max == min)}
*/
public void setXscale(double min, double max) {
double size = max - min;
if (size == 0.0) {
throw new IllegalArgumentException(\"the min and max are the same\");
}
xmin = min - BORDER * size;
xmax = max + BORDER * size;
}
/**
* Sets the y-scale to the specified range.
*
* @param min the minimum valu.
SaveI need help with this maze gui that I wrote in java, I am tryi.pdfarihantstoneart
Save
I need help with this maze gui that I wrote in java, I am trying to find the shortest path but I dont
know how to implement the FindshortestPath Method.
I was given this as a stragedy to solve the findshortestpathMethod():
Create two LinkedLists of MazeMap objects. One will be the list of map objects for cells at
distance x from the center. The other will be the list of map objects for cells at distance x + 1.
Initialize the list at distance x to contain a MazeMap object which refers to the center cell of the
maze. Since this map object refers to the center cell, it does not need to refer to any other
MazeMap object, so its MazeMap reference can be set to null. Set the center cell’s visited field
to true to indicate that this cell has already been added to the map.
Set up a loop to run until the maze entrance is mapped. This loop does the following:
Set up a loop to process each map object from the list at distance x. This loop does the following:
i.Get the cell from the map object
ii.If this cell is the entrance cell, set the entrance and break out of the loop!
iii.Check each direction from this cell and for an accessible neighbor cell
Get a reference to that neighbor cell
If the neighbor cell has not already been visited
Set the cell’s visited field to true so its only processed once
Create a MazeMap object that refers to this neighbor cell
Make this MazeMap object refer to the current map object being processed – ie the cell one step
closer to center
Add this MazeMap object to the list at distance x + 1
List at distance x has been processed. The list at distance x + 1 is now complete, so make the list
at distance x refer to list at distance x + 1. Then create a new empty list for the list at distance x +
1.
At this point, the entrance points at the map object which refers to cell 1,1. That map object also
refers to a map object which is one step closer to the center. Write a loop that traverses this trail
of references until it reaches the end (a null reference). For each map object:
Get the cell referred to.
Call the drawCircle method with a color, the cell’s row and column, and SMALL.
Call the delay method with a SHORT delay. This slows down the drawing process so you can
watch the path being displayed.
Advance to the next map object in the list.
here is the code so far*********
here is my code: ******mazeApp*******
package mazepackage;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.TextInputDialog;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class MazeApp extends Application
{
// default canvas size is DEFAULT_SIZE-by-DEFAULT_SIZE
private static final int DEFAULT_SIZE = 768;
private int width = DEFAULT_SIZE;
private int height = DEFAULT_SIZE;
// The graphics context is needed to enable drawing on the canvas
private Graphics.
An introduction to making browser based games in JavaScript and HTML5.
This workshop was presented at an open day for the Academy of Interactive Entertainment in Sydney, Australia on November 17, 2012.
I need help with this maze gui that I wrote in java, I am trying to .pdfarihantgiftgallery
I need help with this maze gui that I wrote in java, I am trying to find the shortest path but I dont
know how to implement the FindshortestPath Method.
using a BREADTH FIRST SEARCH and the stradgey below to ONLY FIND THE SHORTEST
PATH, the method \"FindshortestPath(); is the only part you need to add code too.
I was given this as a stragedy to solve the findshortestpathMethod():
Create two LinkedLists of MazeMap objects. One will be the list of map objects for cells at
distance x from the center. The other will be the list of map objects for cells at distance x + 1.
Initialize the list at distance x to contain a MazeMap object which refers to the center cell of the
maze. Since this map object refers to the center cell, it does not need to refer to any other
MazeMap object, so its MazeMap reference can be set to null. Set the center cell’s visited field
to true to indicate that this cell has already been added to the map.
Set up a loop to run until the maze entrance is mapped. This loop does the following:
Set up a loop to process each map object from the list at distance x. This loop does the following:
i.Get the cell from the map object
ii.If this cell is the entrance cell, set the entrance and break out of the loop!
iii.Check each direction from this cell and for an accessible neighbor cell
Get a reference to that neighbor cell
If the neighbor cell has not already been visited
Set the cell’s visited field to true so its only processed once
Create a MazeMap object that refers to this neighbor cell
Make this MazeMap object refer to the current map object being processed – ie the cell one step
closer to center
Add this MazeMap object to the list at distance x + 1
List at distance x has been processed. The list at distance x + 1 is now complete, so make the list
at distance x refer to list at distance x + 1. Then create a new empty list for the list at distance x +
1.
At this point, the entrance points at the map object which refers to cell 1,1. That map object also
refers to a map object which is one step closer to the center. Write a loop that traverses this trail
of references until it reaches the end (a null reference). For each map object:
Get the cell referred to.
Call the drawCircle method with a color, the cell’s row and column, and SMALL.
Call the delay method with a SHORT delay. This slows down the drawing process so you can
watch the path being displayed.
Advance to the next map object in the list.
here is the code so far*********
package mazepackage;
import java.util.LinkedList;
import java.util.Random;
import javafx.scene.paint.Color;
public class Maze {
private int N; // dimension of maze
private MazeCell[][] maze;
private Random rand = new Random();
// Used to signal the maze has been solved
private boolean done;
// time in milliseconds (from currentTimeMillis()) when we can draw again
// used to control the frame rate
private long nextDraw = -1;
private MazeApp mf;
// Define constants for the circle size
private final double BI.
I wanted to change the cloudsrectangles into an actuall image it do.pdffeelinggifts
I wanted to change the clouds/rectangles into an actuall image it doesnt matter the image.
import javax.swing.*;
import java.awt.*;
/**
* Created by Thomas on 11/27/2016.
*/
public class Renderer extends JPanel{
//private static final long serialVersionUID = 1L;
protected void paintComponent(Graphics g) {
Main.main.repaint(g);
}
public static int clamp(int greenValue, int i, int j) {
// TODO Auto-generated method stub
return 0;
}
}
OTHER PART:
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ArrayList;
import java.util.Random;
import javax.swing.*;
/**
* Created by Thomas on 11/27/2016.
*/
public class Main implements ActionListener, KeyListener{
public static Main main;
public final int WIDTH = 1400;
public final int HEIGHT = 600;
public HUD Hud;
public Renderer renderer;
public Rectangle character;
public ArrayList cloud;
public Random rand;
public boolean start = false, gameover = false;
public int tick;
public Main() {
JFrame jFrame = new JFrame();
Timer timer = new Timer(20, this);
renderer = new Renderer();
rand = new Random();
jFrame.setTitle(\"Example\");
jFrame.add(renderer);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.setSize(WIDTH, HEIGHT);
jFrame.addKeyListener(this);
jFrame.setVisible(true);
cloud = new ArrayList();
character = new Rectangle(200, 220, 20, 20);
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
timer.start();
}
public void repaint(Graphics g) {
g.setColor(Color.black);
g.fillRect(0,0, WIDTH, HEIGHT);
g.setColor(Color.blue);
g.fillRect(0, HEIGHT - 100, WIDTH, 100);
g.setColor(Color.green);
g.fillRect(character.x, character.y, character.width, character.height);
if (character.y >= HEIGHT - 100 || character.y < 0) {
gameover = true;
}
for (Rectangle rect : cloud) {
g.setColor(Color.white);
g.fillRect(rect.x, rect.y, rect.width, rect.height);
}
g.setColor(Color.WHITE);
g.setFont(new Font(\"Times New Roman\", 1 ,100));
if (!start) {
g.drawString(\"Press to start!\", 450, HEIGHT / 2);
}
else if (gameover) {
g.drawString(\"Game Over!\", 450, HEIGHT / 2);
}
}
public void addCloud(boolean start) {
int width = 400;
int height = 200;
if (start) {
cloud.add(new Rectangle(WIDTH + width + cloud.size() * 300, rand.nextInt(HEIGHT-120),
80, 100));
}
else {
cloud.add(new Rectangle(cloud.get(cloud.size() - 1).x + 300, rand.nextInt(HEIGHT-120), 80,
100));
}
}
public void flap() {
if (gameover) {
character = new Rectangle(300, 400, 40, 40);
cloud.clear();
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
gameover = false;
}
if (!start) {
start = true;
}
else if (!gameover) {
character.y -= 70;
tick = 0;
}
}
@Override
public void actionPerformed(ActionEvent e) {
int speed = 15;
//System.out.println(\"Space\");
if (start) {
for (int i = 0; i .
SaveI need help with this maze gui that I wrote in java, I am tryi.pdfarihantstoneart
Save
I need help with this maze gui that I wrote in java, I am trying to find the shortest path but I dont
know how to implement the FindshortestPath Method.
I was given this as a stragedy to solve the findshortestpathMethod():
Create two LinkedLists of MazeMap objects. One will be the list of map objects for cells at
distance x from the center. The other will be the list of map objects for cells at distance x + 1.
Initialize the list at distance x to contain a MazeMap object which refers to the center cell of the
maze. Since this map object refers to the center cell, it does not need to refer to any other
MazeMap object, so its MazeMap reference can be set to null. Set the center cell’s visited field
to true to indicate that this cell has already been added to the map.
Set up a loop to run until the maze entrance is mapped. This loop does the following:
Set up a loop to process each map object from the list at distance x. This loop does the following:
i.Get the cell from the map object
ii.If this cell is the entrance cell, set the entrance and break out of the loop!
iii.Check each direction from this cell and for an accessible neighbor cell
Get a reference to that neighbor cell
If the neighbor cell has not already been visited
Set the cell’s visited field to true so its only processed once
Create a MazeMap object that refers to this neighbor cell
Make this MazeMap object refer to the current map object being processed – ie the cell one step
closer to center
Add this MazeMap object to the list at distance x + 1
List at distance x has been processed. The list at distance x + 1 is now complete, so make the list
at distance x refer to list at distance x + 1. Then create a new empty list for the list at distance x +
1.
At this point, the entrance points at the map object which refers to cell 1,1. That map object also
refers to a map object which is one step closer to the center. Write a loop that traverses this trail
of references until it reaches the end (a null reference). For each map object:
Get the cell referred to.
Call the drawCircle method with a color, the cell’s row and column, and SMALL.
Call the delay method with a SHORT delay. This slows down the drawing process so you can
watch the path being displayed.
Advance to the next map object in the list.
here is the code so far*********
here is my code: ******mazeApp*******
package mazepackage;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.TextInputDialog;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class MazeApp extends Application
{
// default canvas size is DEFAULT_SIZE-by-DEFAULT_SIZE
private static final int DEFAULT_SIZE = 768;
private int width = DEFAULT_SIZE;
private int height = DEFAULT_SIZE;
// The graphics context is needed to enable drawing on the canvas
private Graphics.
An introduction to making browser based games in JavaScript and HTML5.
This workshop was presented at an open day for the Academy of Interactive Entertainment in Sydney, Australia on November 17, 2012.
I need help with this maze gui that I wrote in java, I am trying to .pdfarihantgiftgallery
I need help with this maze gui that I wrote in java, I am trying to find the shortest path but I dont
know how to implement the FindshortestPath Method.
using a BREADTH FIRST SEARCH and the stradgey below to ONLY FIND THE SHORTEST
PATH, the method \"FindshortestPath(); is the only part you need to add code too.
I was given this as a stragedy to solve the findshortestpathMethod():
Create two LinkedLists of MazeMap objects. One will be the list of map objects for cells at
distance x from the center. The other will be the list of map objects for cells at distance x + 1.
Initialize the list at distance x to contain a MazeMap object which refers to the center cell of the
maze. Since this map object refers to the center cell, it does not need to refer to any other
MazeMap object, so its MazeMap reference can be set to null. Set the center cell’s visited field
to true to indicate that this cell has already been added to the map.
Set up a loop to run until the maze entrance is mapped. This loop does the following:
Set up a loop to process each map object from the list at distance x. This loop does the following:
i.Get the cell from the map object
ii.If this cell is the entrance cell, set the entrance and break out of the loop!
iii.Check each direction from this cell and for an accessible neighbor cell
Get a reference to that neighbor cell
If the neighbor cell has not already been visited
Set the cell’s visited field to true so its only processed once
Create a MazeMap object that refers to this neighbor cell
Make this MazeMap object refer to the current map object being processed – ie the cell one step
closer to center
Add this MazeMap object to the list at distance x + 1
List at distance x has been processed. The list at distance x + 1 is now complete, so make the list
at distance x refer to list at distance x + 1. Then create a new empty list for the list at distance x +
1.
At this point, the entrance points at the map object which refers to cell 1,1. That map object also
refers to a map object which is one step closer to the center. Write a loop that traverses this trail
of references until it reaches the end (a null reference). For each map object:
Get the cell referred to.
Call the drawCircle method with a color, the cell’s row and column, and SMALL.
Call the delay method with a SHORT delay. This slows down the drawing process so you can
watch the path being displayed.
Advance to the next map object in the list.
here is the code so far*********
package mazepackage;
import java.util.LinkedList;
import java.util.Random;
import javafx.scene.paint.Color;
public class Maze {
private int N; // dimension of maze
private MazeCell[][] maze;
private Random rand = new Random();
// Used to signal the maze has been solved
private boolean done;
// time in milliseconds (from currentTimeMillis()) when we can draw again
// used to control the frame rate
private long nextDraw = -1;
private MazeApp mf;
// Define constants for the circle size
private final double BI.
I wanted to change the cloudsrectangles into an actuall image it do.pdffeelinggifts
I wanted to change the clouds/rectangles into an actuall image it doesnt matter the image.
import javax.swing.*;
import java.awt.*;
/**
* Created by Thomas on 11/27/2016.
*/
public class Renderer extends JPanel{
//private static final long serialVersionUID = 1L;
protected void paintComponent(Graphics g) {
Main.main.repaint(g);
}
public static int clamp(int greenValue, int i, int j) {
// TODO Auto-generated method stub
return 0;
}
}
OTHER PART:
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ArrayList;
import java.util.Random;
import javax.swing.*;
/**
* Created by Thomas on 11/27/2016.
*/
public class Main implements ActionListener, KeyListener{
public static Main main;
public final int WIDTH = 1400;
public final int HEIGHT = 600;
public HUD Hud;
public Renderer renderer;
public Rectangle character;
public ArrayList cloud;
public Random rand;
public boolean start = false, gameover = false;
public int tick;
public Main() {
JFrame jFrame = new JFrame();
Timer timer = new Timer(20, this);
renderer = new Renderer();
rand = new Random();
jFrame.setTitle(\"Example\");
jFrame.add(renderer);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.setSize(WIDTH, HEIGHT);
jFrame.addKeyListener(this);
jFrame.setVisible(true);
cloud = new ArrayList();
character = new Rectangle(200, 220, 20, 20);
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
timer.start();
}
public void repaint(Graphics g) {
g.setColor(Color.black);
g.fillRect(0,0, WIDTH, HEIGHT);
g.setColor(Color.blue);
g.fillRect(0, HEIGHT - 100, WIDTH, 100);
g.setColor(Color.green);
g.fillRect(character.x, character.y, character.width, character.height);
if (character.y >= HEIGHT - 100 || character.y < 0) {
gameover = true;
}
for (Rectangle rect : cloud) {
g.setColor(Color.white);
g.fillRect(rect.x, rect.y, rect.width, rect.height);
}
g.setColor(Color.WHITE);
g.setFont(new Font(\"Times New Roman\", 1 ,100));
if (!start) {
g.drawString(\"Press to start!\", 450, HEIGHT / 2);
}
else if (gameover) {
g.drawString(\"Game Over!\", 450, HEIGHT / 2);
}
}
public void addCloud(boolean start) {
int width = 400;
int height = 200;
if (start) {
cloud.add(new Rectangle(WIDTH + width + cloud.size() * 300, rand.nextInt(HEIGHT-120),
80, 100));
}
else {
cloud.add(new Rectangle(cloud.get(cloud.size() - 1).x + 300, rand.nextInt(HEIGHT-120), 80,
100));
}
}
public void flap() {
if (gameover) {
character = new Rectangle(300, 400, 40, 40);
cloud.clear();
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
gameover = false;
}
if (!start) {
start = true;
}
else if (!gameover) {
character.y -= 70;
tick = 0;
}
}
@Override
public void actionPerformed(ActionEvent e) {
int speed = 15;
//System.out.println(\"Space\");
if (start) {
for (int i = 0; i .
Being a slow interpreter, Python may drive a system to deliver utmost speed if some guidelines are followed. The key is to treat programming languages as syntactic sugar to the machine code. It expedites the workflow of timing, iterative design, automatic testing, optimization, and realize an HPC system balancing the time to market and quality of code.
Speed is the king. 10x productive developers change business. So does 10x faster code. Python is 100x slower than C++ but it only matters when you really use Python to implement number-crunching algorithms. We should not do that, and instead go directly with C++ for speed. It calls for strict disciplines of software engineering and code quality, but it should be noted that here the quality is defined by the runtime and the time to market.
The presentation focuses on the Python side of the development workflow. It is made possible by confining C++ in architecture defined by the Python code, which realizes most of the software engineering. The room for writing fast C++ code is provided by pybind11 and careful design of typed data objects. The data objects hold memory buffers exposed to Python as numpy ndarrays for direct access for speed.
Java Question help needed In the program Fill the Add statements.pdfkamdinrossihoungma74
Item 8 Singly ionized (one electron removed) atoms are accelerated and then passed through a
velocity selector consisting of perpendicular electric and magnetic fields. The electric field is 158
V/m and the magnetic field is 3.13 Times 10^2 T. The ions next enter a uniform magnetic field
of magnitude 1.73 Times 10^-2 T that is oriented perpendicular to their velocity. How fast are
the ions moving when they emerge from the velocity selector? If the radius of the path of the
ions in the second magnetic field is 17.4 cm, what is their mass?
Solution
A)
In Velocity selector Electric field & Magnetic field forces on ions are equal & opposite ,this is
because it allows ions with a particular velocity only passes undeflected.
so we can say,
Bqv = Eq
B:magnetic field density
E:Electric field
v:velocity at which the ions remains undeflected.
v=E/B
v = 158V/m / 3.13*10-2 T
=> v = 4.78*103 m/s
B)
as it enteres next in uniform magnetic field of value B=1.73*10-2 T
Work done in uniform magnetic field is zero.It only changes the direction.So B provides
centripetal force for the ions while changing direction in circular path of radius r=17.4cm.
Bqv = mv²/r
m = Bqr / v = (1.73*10-2T)(1.6*10-19C)(0.174m) / (4.78*103m/s)
=>m = 1*10-25 kg.
Not so long ago Microsoft announced a new language trageting on front-end developers. Everybody's reaction was like: Why?!! Is it just Microsoft darting back to Google?!
So, why a new language? JavaScript has its bad parts. Mostly you can avoid them or workaraund. You can emulate class-based OOP style, modules, scoping and even run-time typing. But that is doomed to be clumsy. That's not in the language design. Google has pointed out these flaws, provided a new language and failed. Will the story of TypeScript be any different?
This is Function Class public abstract class Function { .pdfamitbagga0808
//This is Function Class
public abstract class Function {
/**
* Calculates the value f(x) of the function at x
* @param x The x-value at which the function will be evaluated
* @return a double, the value of the function at x
*/
public abstract double fnValue(double x);
/**
* Translates f(x) to the display coordinate system. Note that Java graphics
* places (0,0) in the upper left, and (xmax, ymax) in the lower right of the
* display. A buffer of 5 pixels is kept at top and bottom.
* @param x the value at which f(x) will be evaluated
* @param d the height in pixels of the display
* @param minY the minimum f(x) to be displayed, over the extent of the x\'s
* @param maxY the maximum f(x) to be displayed, over the extent of the x\'s
* @return the value of f(x) translated to the display coordinate system
*/
public double fnValueToPlot(double x, double d, double minY, double maxY) {
double y = fnValue(x);
double yDraw = (d+5)-((y-minY)*(d/(maxY-minY)));
return yDraw;
}
/**
* Determines the display value where y=0
* @param height Height of the Canvas
* @param minY th=0e minimum height of the function within the chosen extents
* @param maxY the maximum height of the function within the chosen extents
* @return the value of y to display corresponding to y
*/
public double originToPlot(double height, double minY, double maxY) {
double yDraw = (height+5)-((0-minY)*(height/(maxY-minY)));
return yDraw;
}
}
//This is GraphManager Class
public class GraphManager implements GraphManagerInterface {
private double xLeft, xRight;
private double yTop = Integer.MIN_VALUE;
private double yBottom = Integer.MAX_VALUE;
private int functionChoice=-999;
Function function1, function2, function3, function4, function5, function6;
/**
* Constructor instantiates the functions specified.
*/
GraphManager() {
function1 = new Function1();
function2 = new Function2();
function3 = new Function3();
}
/**
* getFnValue calculates the value of the function requested by the user, at a specific x value.
* @param fnNum the choice of which function to evaluate
* @param x the value at which to evaluate the function
* @return the value of f(x)
*/
public double getFnValue (int fnNum, double x) {
switch(fnNum) {
case 1: return function1.fnValue(x);
case 2: return function2.fnValue(x);
case 3: return function3.fnValue(x);
default: return 0;
}
}
/**
* Sets the function choice
* @param choice an integer indexing the function desired
*/
public void setFunctionChoice(int choice) {
functionChoice = choice;
}
/**
* Gets the function index previously selected by the user
* @return an index 1-4 corresponding to a function
*/
public int getFunctionChoice() {
return functionChoice;
}
/**
* Gets the actual function instance
* @param choice the index of the function desired
* @return an instance of a sub-class of the Function class
*/
public Function getFunction(int choice) {
switch(choice) {
case 1: return function1;
case 2: return function2;
case 3: return function3;
default: return null;
}
}
/**
* Sets.
You are presented with a patient, named Gerry, who has Down syndrome .pdfarcotstarsports
You are presented with a patient, named Gerry, who has Down syndrome (trisomy 21). You
determine that the nondisjunction event occurred in his mother, named Mary, during meiosis I.
You are interested in the TPTE gene, which is near the centromere of chromosome 21. Virtually
no recombination occurs between the centromere and the TPTE gene. Mary has two different
alleles of the TPTE gene. Would Gerry\'s two chromosome 21s from his mother have the same
or different alleles of the TPTE gene? Or do you not have enough information to decide?
Explain your answer by drawing meiosis I and II for Mary\'s chromosome 21. Use \"A\" for one
allele and \"a\" for the other allele of the TPTE gene. Only draw the chromosomes relevant to
this question (Do not draw all 46 chromosomes).
Solution
a. Nondisjunction produces abnormal gametes. Nondisjunction in meiosis I occurs during
anaphase I when one pair of homologous chromosomes fails to separate.Trisomy is the condition
of having 3 copies of one chromosome type. It is designated as 2n + 1 because the cell has the
normal two sets of each 23 types of chromosomes plus an extra copy of one chromosome.
I think Gerrys two chromosome 21s from his mother have different alleles (A and a) of the TPTE
gene. But more information could be needed to explain and understand this in a much better way..
Write a template function to fill in a STL list with a given array..pdfarcotstarsports
Write a template function to fill in a STL list with a given array.
Solution
Hi, I am not able to see the function prototype completely.
But I wrote a function that takes a template array and adding all elements of array in STL list.
Please let me know in case of any issue.
template
void fillArray(T arr[], int size) {
// creating STL list of type T
std::list myList;
// adding each element from arr in list
for(int i=0; i.
More Related Content
Similar to need help with code I wrote. This code is a maze gui, and i need hel.pdf
Being a slow interpreter, Python may drive a system to deliver utmost speed if some guidelines are followed. The key is to treat programming languages as syntactic sugar to the machine code. It expedites the workflow of timing, iterative design, automatic testing, optimization, and realize an HPC system balancing the time to market and quality of code.
Speed is the king. 10x productive developers change business. So does 10x faster code. Python is 100x slower than C++ but it only matters when you really use Python to implement number-crunching algorithms. We should not do that, and instead go directly with C++ for speed. It calls for strict disciplines of software engineering and code quality, but it should be noted that here the quality is defined by the runtime and the time to market.
The presentation focuses on the Python side of the development workflow. It is made possible by confining C++ in architecture defined by the Python code, which realizes most of the software engineering. The room for writing fast C++ code is provided by pybind11 and careful design of typed data objects. The data objects hold memory buffers exposed to Python as numpy ndarrays for direct access for speed.
Java Question help needed In the program Fill the Add statements.pdfkamdinrossihoungma74
Item 8 Singly ionized (one electron removed) atoms are accelerated and then passed through a
velocity selector consisting of perpendicular electric and magnetic fields. The electric field is 158
V/m and the magnetic field is 3.13 Times 10^2 T. The ions next enter a uniform magnetic field
of magnitude 1.73 Times 10^-2 T that is oriented perpendicular to their velocity. How fast are
the ions moving when they emerge from the velocity selector? If the radius of the path of the
ions in the second magnetic field is 17.4 cm, what is their mass?
Solution
A)
In Velocity selector Electric field & Magnetic field forces on ions are equal & opposite ,this is
because it allows ions with a particular velocity only passes undeflected.
so we can say,
Bqv = Eq
B:magnetic field density
E:Electric field
v:velocity at which the ions remains undeflected.
v=E/B
v = 158V/m / 3.13*10-2 T
=> v = 4.78*103 m/s
B)
as it enteres next in uniform magnetic field of value B=1.73*10-2 T
Work done in uniform magnetic field is zero.It only changes the direction.So B provides
centripetal force for the ions while changing direction in circular path of radius r=17.4cm.
Bqv = mv²/r
m = Bqr / v = (1.73*10-2T)(1.6*10-19C)(0.174m) / (4.78*103m/s)
=>m = 1*10-25 kg.
Not so long ago Microsoft announced a new language trageting on front-end developers. Everybody's reaction was like: Why?!! Is it just Microsoft darting back to Google?!
So, why a new language? JavaScript has its bad parts. Mostly you can avoid them or workaraund. You can emulate class-based OOP style, modules, scoping and even run-time typing. But that is doomed to be clumsy. That's not in the language design. Google has pointed out these flaws, provided a new language and failed. Will the story of TypeScript be any different?
This is Function Class public abstract class Function { .pdfamitbagga0808
//This is Function Class
public abstract class Function {
/**
* Calculates the value f(x) of the function at x
* @param x The x-value at which the function will be evaluated
* @return a double, the value of the function at x
*/
public abstract double fnValue(double x);
/**
* Translates f(x) to the display coordinate system. Note that Java graphics
* places (0,0) in the upper left, and (xmax, ymax) in the lower right of the
* display. A buffer of 5 pixels is kept at top and bottom.
* @param x the value at which f(x) will be evaluated
* @param d the height in pixels of the display
* @param minY the minimum f(x) to be displayed, over the extent of the x\'s
* @param maxY the maximum f(x) to be displayed, over the extent of the x\'s
* @return the value of f(x) translated to the display coordinate system
*/
public double fnValueToPlot(double x, double d, double minY, double maxY) {
double y = fnValue(x);
double yDraw = (d+5)-((y-minY)*(d/(maxY-minY)));
return yDraw;
}
/**
* Determines the display value where y=0
* @param height Height of the Canvas
* @param minY th=0e minimum height of the function within the chosen extents
* @param maxY the maximum height of the function within the chosen extents
* @return the value of y to display corresponding to y
*/
public double originToPlot(double height, double minY, double maxY) {
double yDraw = (height+5)-((0-minY)*(height/(maxY-minY)));
return yDraw;
}
}
//This is GraphManager Class
public class GraphManager implements GraphManagerInterface {
private double xLeft, xRight;
private double yTop = Integer.MIN_VALUE;
private double yBottom = Integer.MAX_VALUE;
private int functionChoice=-999;
Function function1, function2, function3, function4, function5, function6;
/**
* Constructor instantiates the functions specified.
*/
GraphManager() {
function1 = new Function1();
function2 = new Function2();
function3 = new Function3();
}
/**
* getFnValue calculates the value of the function requested by the user, at a specific x value.
* @param fnNum the choice of which function to evaluate
* @param x the value at which to evaluate the function
* @return the value of f(x)
*/
public double getFnValue (int fnNum, double x) {
switch(fnNum) {
case 1: return function1.fnValue(x);
case 2: return function2.fnValue(x);
case 3: return function3.fnValue(x);
default: return 0;
}
}
/**
* Sets the function choice
* @param choice an integer indexing the function desired
*/
public void setFunctionChoice(int choice) {
functionChoice = choice;
}
/**
* Gets the function index previously selected by the user
* @return an index 1-4 corresponding to a function
*/
public int getFunctionChoice() {
return functionChoice;
}
/**
* Gets the actual function instance
* @param choice the index of the function desired
* @return an instance of a sub-class of the Function class
*/
public Function getFunction(int choice) {
switch(choice) {
case 1: return function1;
case 2: return function2;
case 3: return function3;
default: return null;
}
}
/**
* Sets.
You are presented with a patient, named Gerry, who has Down syndrome .pdfarcotstarsports
You are presented with a patient, named Gerry, who has Down syndrome (trisomy 21). You
determine that the nondisjunction event occurred in his mother, named Mary, during meiosis I.
You are interested in the TPTE gene, which is near the centromere of chromosome 21. Virtually
no recombination occurs between the centromere and the TPTE gene. Mary has two different
alleles of the TPTE gene. Would Gerry\'s two chromosome 21s from his mother have the same
or different alleles of the TPTE gene? Or do you not have enough information to decide?
Explain your answer by drawing meiosis I and II for Mary\'s chromosome 21. Use \"A\" for one
allele and \"a\" for the other allele of the TPTE gene. Only draw the chromosomes relevant to
this question (Do not draw all 46 chromosomes).
Solution
a. Nondisjunction produces abnormal gametes. Nondisjunction in meiosis I occurs during
anaphase I when one pair of homologous chromosomes fails to separate.Trisomy is the condition
of having 3 copies of one chromosome type. It is designated as 2n + 1 because the cell has the
normal two sets of each 23 types of chromosomes plus an extra copy of one chromosome.
I think Gerrys two chromosome 21s from his mother have different alleles (A and a) of the TPTE
gene. But more information could be needed to explain and understand this in a much better way..
Write a template function to fill in a STL list with a given array..pdfarcotstarsports
Write a template function to fill in a STL list with a given array.
Solution
Hi, I am not able to see the function prototype completely.
But I wrote a function that takes a template array and adding all elements of array in STL list.
Please let me know in case of any issue.
template
void fillArray(T arr[], int size) {
// creating STL list of type T
std::list myList;
// adding each element from arr in list
for(int i=0; i.
write a method to generate AVL tree of height h wth fewest nodes and.pdfarcotstarsports
write a method to generate AVL tree of height h wth fewest nodes and what is the running time
of your method
Solution
class Node {
int key, height;
Node left, right;
Node(int d) {
key = d;
height = 1;
}
}
class AVLTree {
static Node root;
// A utility function to get height of the tree
int height(Node N) {
if (N == null) {
return 0;
}
return N.height;
}
// A utility function to get maximum of two integers
int max(int a, int b) {
return (a > b) ? a : b;
}
// A utility function to right rotate subtree rooted with y
// See the diagram given above.
Node rightRotate(Node y) {
Node x = y.left;
Node T2 = x.right;
// Perform rotation
x.right = y;
y.left = T2;
// Update heights
y.height = max(height(y.left), height(y.right)) + 1;
x.height = max(height(x.left), height(x.right)) + 1;
// Return new root
return x;
}
// A utility function to left rotate subtree rooted with x
// See the diagram given above.
Node leftRotate(Node x) {
Node y = x.right;
Node T2 = y.left;
// Perform rotation
y.left = x;
x.right = T2;
// Update heights
x.height = max(height(x.left), height(x.right)) + 1;
y.height = max(height(y.left), height(y.right)) + 1;
// Return new root
return y;
}
// Get Balance factor of node N
int getBalance(Node N) {
if (N == null) {
return 0;
}
return height(N.left) - height(N.right);
}
Node insert(Node node, int key) {
/* 1. Perform the normal BST rotation */
if (node == null) {
return (new Node(key));
}
if (key < node.key) {
node.left = insert(node.left, key);
} else {
node.right = insert(node.right, key);
}
/* 2. Update height of this ancestor node */
node.height = max(height(node.left), height(node.right)) + 1;
/* 3. Get the balance factor of this ancestor node to check whether
this node became unbalanced */
int balance = getBalance(node);
// If this node becomes unbalanced, then there are 4 cases
// Left Left Case
if (balance > 1 && key < node.left.key) {
return rightRotate(node);
}
// Right Right Case
if (balance < -1 && key > node.right.key) {
return leftRotate(node);
}
// Left Right Case
if (balance > 1 && key > node.left.key) {
node.left = leftRotate(node.left);
return rightRotate(node);
}
// Right Left Case
if (balance < -1 && key < node.right.key) {
node.right = rightRotate(node.right);
return leftRotate(node);
}
/* return the (unchanged) node pointer */
return node;
}
// A utility function to print preorder traversal of the tree.
// The function also prints height of every node
void preOrder(Node node) {
if (node != null) {
System.out.print(node.key + \" \");
preOrder(node.left);
preOrder(node.right);
}
}
public static void main(String[] args) {
AVLTree tree = new AVLTree();
/* Constructing a tree with random values */
root = tree.insert(root, 10);
root = tree.insert(root, 20);
root = tree.insert(root, 30);
root = tree.insert(root, 40);
root = tree.insert(root, 50);
root = tree.insert(root, 25);
System.out.println(\"The preorder traversal of constructed tree is : \");
tree.preOrder(root);
}
}
The running time of this method is O(h)..
Which of the following is NOT correctWhich of the following is NO.pdfarcotstarsports
Which of the following is NOT correct?
Which of the following is NOT correct?-Protozoans are fairly susceptible to antimicrobial
controls, but their cysts are resistant.-Naked viruses are more susceptible to antimicrobial
control agents than are enveloped viruses.-The antimicrobial effect of heat is enhanced by acidic
conditions.-Warm disinfectants generally work better than cool ones.
Solution
The answer is -Naked viruses are more susceptible to antimicrobial control agents than are
enveloped viruses..
What is Mills response to the problem posed by some peoples desi.pdfarcotstarsports
What is Mill\'s response to the problem posed by some people\'s desire for virtue for its own
sake?Tthis is except from Utilitarianism.
Solution
John Stuart Mill wrote his moral treatise, Utilitarianism, in a period in intellectual history
dominated by Aristotelian virtue and Kantian deontology, as well as the intensely conservative
political and social climate of Victorian England.Utilitarianism was intended to convince the
public of Mill’s first principle. Mill responds to preexisting ethical frameworks, namely virtue
ethics, deontology, Christian ethics, and egoism. Except for egoism, Mill invariably shows how
other moral theories and values are actually or can become part of his first principle. The most
prominent response in the text is his amalgamation of virtue ethics, which spans all of Chapter 4.
Mill is successful in his synthesis of virtue ethics, despite philosophical sloppiness and logical
fallacies. In his success, Mill crafted an impartial standard which the moral claims of other
theories can by compared against.
It is in Chapter 4 of Utilitarianism that Mill addresses virtue the most directly. He begins his
argument by stating that virtue can actually be an end to human action besides happiness. Mill
agrees with his opponents that there are people who desire or approve of acts according to virtue
and absence of vice instead of the pleasure and the absence of pain. The reason this is significant
is because if this is a descriptive fact, a truth, then it would pose a problem for Mill’s inductive
proof of Utility, which hinges on the observation that happiness is desired and therefore
desirable. If there are people who genuinely value virtue as the criteria of right and wrong, of
how one should act, then, at very least, happiness is not the only first principle, which is what the
Utilitarian claims. The solution to this problem for utilitarianism is to either swallow the
intuitively unsavory conclusion that virtue is without value, or show that virtue actually has
value belonging to, part of, or from happiness.
Mill states that where opponents make their mistake is in believing that utility is incompatible
with virtue. Mill holds that virtue is not only valuable as a means to pleasure, but in fact as an
end in itself. Virtue and happiness are perceived to be different, but Mill attempts to show that
this is superficial. It is by seeking virtue disinterestedly and for its own sake that virtue can
become part of pleasure, Mill claims.
So not only is Mill successful in bringing virtue ethics into utilitarianism, but he’s successful in
creating a template by which other theories can be synthesized with utility. Mill’s claim is that
all moral sentiments stem from a first principle that does not admit of proof, and that that first
principle is the concept of utility. By providing one specific example, virtue, and showing how it
actually admits of his general concept, utility, Mill is successful crafting an argument which
allows people .
What is a bivariate distributionSolutionBivariate distributio.pdfarcotstarsports
What is a bivariate distribution?
Solution
Bivariate distribution is a two dimensional random variables distribution.
When the two random variables X and Y are discrete, the joint probability
mass function is defined as P(x,y) = P(X=x, Y=y).
When the two random variables X and Y are continuous, the joint probability
density function is given by f(x,y).
What are some of the tools you can use to tune or correct a Linux fi.pdfarcotstarsports
What are some of the tools you can use to tune or correct a Linux filesystem?
Solution
Some of the tools are Process Activity Command(it gives the real time view of system and we
can keep an eye to factors which are affecting the performance.iptraf which gives the network
statistics and other one could be /proc file system which gives the detailed information about
harware devices connected and kernel information. Nagios is an open source system which give
complete control over all the information like host, network traffic , equipments and it will send
alert when something goes wrong. Another one could be Cacti which is web based monitoring
tool, its a network graphing tool which gives the statistics in the form of graphs.
TrueFalse Insulin spikes in the postabsorptive state.Solution.pdfarcotstarsports
True/False: Insulin spikes in the postabsorptive state.
Solution
This statement is false. Glucagon stimulates and insulin suppresses the hydrolysis of liver
glycogen, or glycogenolysis. Thus during times of fasting (post absorptive state) , when glucagon
secretion is high and insulin secretion is low, liver glycogen is used as a source of additional
blood glucose..
The principal role of ATP In the cell is A) serving as structural s.pdfarcotstarsports
The principal role of ATP In the cell is: A) serving as structural support. B) catalyzing
chemical reactions. C) keeping the phospholipid tails of membranes aligned D) providing
energy. E) functioning as a hormone. Small nonpolar molecules, such as O_2 and CO_2, enter a
cell by: A) vesicle-mediated transport. B) simple diffusion. C) osmosis. D) facilitated
diffusion. E) active transport. Eukaryotic cells differ from prokaryotic cells in that eukaryotic
cells have: A) plasma membrance B) genetic material C) cytoplasm. D) ribosomes. E)
nucleus. If a plant cell is placed in an aqueous solution that is hypertonic to the cell, the cell A)
build up turgor pressure B) build up wall pressure C) undergo plasmolysis D) neither gain nor
lose water E) swell and perhaps burst
Solution
15 . D Providing energy
Atp or adenosine tri phosphate is a energy rich molecule produced by mitochondria of our cell.
These atp molecules are produced by oxidation of organic molecules, (glucose) which is then
utilised by our body for various cellular functions..
The neutral theory of evolution proposed that most genetic mutations .pdfarcotstarsports
The neutral theory of evolution proposed that most genetic mutations are functionally neutral.
Neutral mutations are fixed in a population by natural selection random genetic drift
environmental selection asexual reproduction the invariance of DNA
Solution
The neutra theory of evouloution proposed that most genetic mutations are functionally
neutral.Neutral mutations are fixed in a population by-
ans- E. the invariance of DNA
(In a population genetics,fixation is the change in a gene pool with atleast two variant of
particular gene or allele).
The oldest living organisms on Earth are plants. Some bristlecone pi.pdfarcotstarsports
The oldest living organisms on Earth are plants. Some bristlecone pines are over 4600 years old,
and a desert creosote bush is known to be 10,000 year old. What special feature of plants
provides for this incredible longevity? How do plant differ from animals in their pattern of
growth and development? (also explain how trees grow upward as too how a nail driven into a
10year old tree will be at the same height 10 years later)
Solution
The oldest living organisms on Earth are plants. Some bristlecone pines are about 4,600 years
old, and a desert creosote bush is known to be 10,000 years old. see actually it is just a matter of
definition. no individual cells last that long time and all the original tissue is typically long dead.
We generally think of it as continuing because the new growth is against the old. growth is
continued and new cells are generated due to plants anaomy structure. they maintain their gene
pool.
trees grow upward as too how a nail driven into a 10year old tree will be at the same height 10
years later because tree grows from the top up.
Differences between Plant Growth and Animal Growth:
in plant growth , generally growth involved most of the parts and increase in the number of parts.
growth generally continuw throughout the life of a plant.
growth can be sessional. it depends on the seassion. it can quit the poisonius things during winter
seasons.
Plant growth carries well defined growing regions like stem, leaf.
seedling has no effect in adult plant.
growing pattern differs species to species in case of plant growth.
new parts can be generated around the older ones.
animal growth here growth takes place before the maturity period. after a certain age there is no
growth in body organs.
there is no increase in number of body parts.
growth pattern is absent generally
the young one is generally identical the old or adult one. ( sexual maturity may be an exception).
Suppose there is a person whose total lung capacity (TLC) is 4.90 L, .pdfarcotstarsports
Suppose there is a person whose total lung capacity (TLC) is 4.90 L, inspiratory reserve volume
(IRV) is 2.75 L, and tidal volume (TV or V_T) is 0.50 L. Calculate this person\'s functional
residual capacity (FRC). FRC =
Solution
Functinal residual capacity = Total lungs capacity- (Inspiratory reserve volume +Tidal volume)
FRC=4.9- (2.75+0.5)
FRC= 4.9- 3.25
FRC= 1.65 L Answer.
Research the IPv4 ns the IPv6 protocols, then prepare a report that .pdfarcotstarsports
Research the IPv4 ns the IPv6 protocols, then prepare a report that explains the likes and
differences of the two protocols and include how and why the transition from IPv4 to IPv6 is to
occur.
Project report body must have 5 pages or more, with Times New Roman12 pt. print double
spaced. Also include a Cover sheet and a Reference page.
Solution
Introductory lines:
The internet protocol or IP specifies and describes the technical details and formats of fragments
of data (Also known as packets.) along with addressing schemes (numerical; actually in binary
but can be interpreted as decimals or hexadecimals assigned to each of the devices connected
through the network) in order to uniquely identify them and create a platform for secure and
reliable communication.
Ipv4 over the years was proved and deployed for communications over the internet. However in
the current days it becomes obsolete and deficient in order to serve the huge and increasing
number of users or network devices.
To make this possible, the IPv6 comes into existence. The IPv6 provides many extra features and
claims to support and serve this increasing number of devices for upcoming coming centuries.
Let’s discuss about the similar and distinct features of both IPv4 and IPv6.
IPv4 in terms of IP addresses, Address allocation, masks and types:
IPv6 in terms of IP addresses, Address allocation, masks and types:
IPv4 in terms of IP header:
Headers in IPv4 are of variable length that varies from 20 to 60 bytes.
IPv4 does not identify packet flow for QOS handling.
It adds checksum filed for identification of transmission errors in the data.
IPv6 in terms of IP header:
Uses fixed length of 40 bytes of headers and there is no concept of option filed in header.
It supports packet flow for QOS by flow level filed.
IPv6 does not implements checksum for error handling.
IPv4 in terms of IP packets ports and security:
IPv4 supports the packet size of 576 bytes.
They also support packet filtering mechanisms through firewalls.
IPv4 supports for port spaces of the range 1 to 65535
IPsec in IPv4 is optional.
IPv6 in terms of IP packets ports and security:
IPv6 supports the packet size of 1280 bytes.
They does not supports packet filtering mechanisms.
The way the portts work both in IPv4 and IPv6 are the same.
IPv6 has inbuilt IPsec support.
IPv4 was successful;;y deployed in 1981 over internet whereas IPv6 was planned to be deployed
from 1999 but could partially deployed till the date.
Why transition from IPv4 to IPv6 must occur ?
The deficiency of IP address of IPv4 type is one of the most eye catching reasons for transition
towards IPv6. Each and every day the Internet is experiencing phenomenal increase of devices
which are being connected and using the internet.
In order to provide services to all the address space of IPv4 seems to be fewer. Hence
a transition from IPv4 to IPv6 is must needed to satisfy such demand of larger address space.
Except this, the other technical features like improve.
Species I Species II Species III Species IV Ancestral sequence IV Sit.pdfarcotstarsports
Species I Species II Species III Species IV Ancestral sequence IV Site 2 3 4 C G A T C T T C A
T A C A G T T IV IV
Solution
Phylogenetic tree also called evolutionary tree is a branched chain diagram that indicates
evolutionary relationship among various species and groups of organisms. Phylogenetic trees
represent the hypothetical evolution.
The most parsimonious phylogenetic tree is E.
Solve the differential equation y+y=sin(x). Im thinking I ne.pdfarcotstarsports
Solve the differential equation y\'\'+y\'=sin(x). I\'m thinking I need to take the integral of both
sides in order to get it in the proper form, but i really don\'t know. Any help is greatly
appreciated, thanks.
Solution
Ya integrate both sides => dy/dx + y = -cosx again integrate =>y+y^2/2 = -sinx + c.
Please do C, D, and E For the given f Z right arrow Z, decide wheth.pdfarcotstarsports
Please do C, D, and E For the given f: Z right arrow Z, decide whether f is onto and whether it is
one-to-one. Prove that your decisions are correct.
Solution
c) onto as range of f(x) is Z and f(x) = odd intergers when x is even , f(x) = even intergers when
x is odd
Thus even integers + odd integers + 0 (when x is -1) = Z
one to one as no element in x will give repeatable values as functions are increasing functions
d) onto as x/2 covers whole range of intergers
not one to one as as only x/2 covers the whole range (when x is even ) , repeated values will
come when x is odd
e) not onto as only multiples of 3 and 2 are getting in the range
not one to one as it will be get repeated many times ( as in case 6 (for x=2) and 6 (for x=3)).
Microbiology question Which of the following is the most unique a.pdfarcotstarsports
Microbiology question :
Which of the following is the most unique aspect of archaeon cell envelopes?
a) The plasma membrane is composed of phospholipids.
b) The cell walls contain a modified type of peptidoglycan.
c) Archaeon capsules can be composed of protein or polysaccharide.
d) Some archaeons have lipid monolayers in their plasma membrane.
Solution
The distinct features is
Some archeons have a lipid monolayer in their plasma memberane..!!!.
Is Event B dependent or independent of Event A A green ball is draw.pdfarcotstarsports
Is Event B dependent or independent of Event A? A green ball is drawn from a box with five
balls and placed next to the box. B: A red ball is drawn next and placed next to the green one.
Please provide detail.
Solution
DEPENDENT
because B is an event that depend of A for the text that say is drawn next and placed next to the
green one.
In this view, the front of the heart has been reflected upwards. Ide.pdfarcotstarsports
In this view, the front of the heart has been reflected upwards. Identify {J}
A. trabeculae carnae of R ventricle
B. chordae tendineae
C. interventricular septum
D. moderator band JE
Solution
J is right auricle since it is situaited at upper right part of the heart and H is left auricle since its
situaited at upper left part..
Biological screening of herbal drugs: Introduction and Need for
Phyto-Pharmacological Screening, New Strategies for evaluating
Natural Products, In vitro evaluation techniques for Antioxidants, Antimicrobial and Anticancer drugs. In vivo evaluation techniques
for Anti-inflammatory, Antiulcer, Anticancer, Wound healing, Antidiabetic, Hepatoprotective, Cardio protective, Diuretics and
Antifertility, Toxicity studies as per OECD guidelines
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
Introduction to AI for Nonprofits with Tapp NetworkTechSoup
Dive into the world of AI! Experts Jon Hill and Tareq Monaur will guide you through AI's role in enhancing nonprofit websites and basic marketing strategies, making it easy to understand and apply.
A Strategic Approach: GenAI in EducationPeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
http://sandymillin.wordpress.com/iateflwebinar2024
Published classroom materials form the basis of syllabuses, drive teacher professional development, and have a potentially huge influence on learners, teachers and education systems. All teachers also create their own materials, whether a few sentences on a blackboard, a highly-structured fully-realised online course, or anything in between. Despite this, the knowledge and skills needed to create effective language learning materials are rarely part of teacher training, and are mostly learnt by trial and error.
Knowledge and skills frameworks, generally called competency frameworks, for ELT teachers, trainers and managers have existed for a few years now. However, until I created one for my MA dissertation, there wasn’t one drawing together what we need to know and do to be able to effectively produce language learning materials.
This webinar will introduce you to my framework, highlighting the key competencies I identified from my research. It will also show how anybody involved in language teaching (any language, not just English!), teacher training, managing schools or developing language learning materials can benefit from using the framework.
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
Francesca Gottschalk - How can education support child empowerment.pptxEduSkills OECD
Francesca Gottschalk from the OECD’s Centre for Educational Research and Innovation presents at the Ask an Expert Webinar: How can education support child empowerment?
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Unit 8 - Information and Communication Technology (Paper I).pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdf
1. need help with code I wrote. This code is a maze gui, and i need help with the method
shorterstpath(); here is my code:
******mazeApp*******
package mazepackage;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.TextInputDialog;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class MazeApp extends Application
{
// default canvas size is DEFAULT_SIZE-by-DEFAULT_SIZE
private static final int DEFAULT_SIZE = 768;
private int width = DEFAULT_SIZE;
private int height = DEFAULT_SIZE;
// The graphics context is needed to enable drawing on the canvas
private GraphicsContext gc;
// boundary of drawing canvas, 0% border
// private static final double BORDER = 0.05;
private static final double BORDER = 0.00;
private double xmin, ymin, xmax, ymax;
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage primaryStage)
{
Group root = new Group();
Canvas canvas = new Canvas(width, height);
gc = canvas.getGraphicsContext2D();
2. gc.setLineWidth(2);
gc.setFill(Color.WHITE);
gc.fillRect(0, 0, width, height);
root.getChildren().add(canvas);
TextInputDialog tid = new TextInputDialog();
tid.setTitle("Maze Size");
tid.setHeaderText("Enter maze size between 10 and 50");
tid.showAndWait();
int size = Integer.parseInt(tid.getResult());
if (size > 50)
size = 50;
if (size < 10)
size = 10;
primaryStage.setTitle("Maze Application");
primaryStage.setScene(new Scene(root));
primaryStage.setResizable(false);
// Make sure that the application goes away when then window is closed
primaryStage.setOnCloseRequest(e -> System.exit(0));
primaryStage.show();
Maze maze = new Maze(this, size);
// Must solve the maze in a separate thread or else
// the GUI wont update until the end.....
Thread solver = new Thread(
new Runnable () {
public void run()
{
while(true)
{
maze.buildAndDrawMaze();
maze.findShortestPath();
try
{
Thread.sleep(5000);
3. }
catch(Exception e) { }
gc.setFill(Color.WHITE);
gc.fillRect(0, 0, width, height);
}
}
});
solver.start();
}
/**
* Sets the pen color to the specified color.
*
* @param color the color to make the pen
*/
public void setPenColor(Color color) {
gc.setStroke(color);
}
/**
* Sets the pen color to the specified color.
*
* @param color the color to make the pen
*/
public void setFillColor(Color color) {
gc.setFill(color);
}
/**
* Sets the x-scale to the specified range.
*
* @param min the minimum value of the x-scale
* @param max the maximum value of the x-scale
* @throws IllegalArgumentException if {@code (max == min)}
*/
public void setXscale(double min, double max) {
double size = max - min;
if (size == 0.0) {
4. throw new IllegalArgumentException("the min and max are the same");
}
xmin = min - BORDER * size;
xmax = max + BORDER * size;
}
/**
* Sets the y-scale to the specified range.
*
* @param min the minimum value of the y-scale
* @param max the maximum value of the y-scale
* @throws IllegalArgumentException if {@code (max == min)}
*/
public void setYscale(double min, double max) {
double size = max - min;
if (size == 0.0) {
throw new IllegalArgumentException("the min and max are the same");
}
ymin = min - BORDER * size;
ymax = max + BORDER * size;
}
// helper functions that scale from user coordinates to screen coordinates and back
private double scaleX(double x) {
return width * (x - xmin) / (xmax - xmin);
}
private double scaleY(double y) {
return height * (ymax - y) / (ymax - ymin);
}
private double factorX(double w) {
return w * width / Math.abs(xmax - xmin);
}
private double factorY(double h) {
return h * height / Math.abs(ymax - ymin);
}
private double userX(double x) {
return xmin + x * (xmax - xmin) / width;
}
5. private double userY(double y) {
return ymax - y * (ymax - ymin) / height;
}
/**
* Draws a line segment between (x0,
* y0) and (x1,
* y1).
*
* @param x0 the x-coordinate of one endpoint
* @param y0 the y-coordinate of one endpoint
* @param x1 the x-coordinate of the other endpoint
* @param y1 the y-coordinate of the other endpoint
*/
public void line(double x0, double y0, double x1, double y1) {
gc.strokeLine(scaleX(x0), scaleY(y0), scaleX(x1), scaleY(y1));
}
/**
* Draws one pixel at (x, y). This method is private
* because pixels depend on the display. To achieve the same effect, set the
* pen radius to 0 and call {@code point()}.
*
* @param x the x-coordinate of the pixel
* @param y the y-coordinate of the pixel
*/
private void pixel(double x, double y) {
gc.fillRect((int) Math.round(scaleX(x)), (int) Math.round(scaleY(y)), 1, 1);
}
/**
* Draws a filled circle of the specified radius, centered at (x,
* y).
*
* @param x the x-coordinate of the center of the circle
* @param y the y-coordinate of the center of the circle
* @param radius the radius of the circle
* @throws IllegalArgumentException if {@code radius} is negative
*/
6. public void filledCircle(double x, double y, double radius) {
double xs = scaleX(x);
double ys = scaleY(y);
double ws = factorX(2 * radius);
double hs = factorY(2 * radius);
if (ws <= 1 && hs <= 1) {
pixel(x, y);
} else {
gc.fillOval(xs - ws / 2, ys - hs / 2, ws, hs);
}
}
}
***********maze.java**************
package mazepackage;
import java.util.LinkedList;
import java.util.Random;
import javafx.scene.paint.Color;
public class Maze {
private int N; // dimension of maze
private MazeCell[][] maze;
private Random rand = new Random();
// Used to signal the maze has been solved
private boolean done;
// time in milliseconds (from currentTimeMillis()) when we can draw again
// used to control the frame rate
private long nextDraw = -1;
private MazeApp mf;
// Define constants for the circle size
private final double BIG = 0.375;
private final double SMALL = 0.25;
// Define constants for the delay times
private final int SHORT = 30;
private final int LONG = 500;
public Maze(MazeApp ma, int n) {
N = n;
mf = ma;
7. mf.setXscale(0, N + 2);
mf.setYscale(0, N + 2);
}
public void buildAndDrawMaze() {
createMaze();
buildMaze();
drawMaze();
}
// create the initial data structures that contain the maze data
private void createMaze() {
maze = new MazeCell[N + 2][N + 2];
for (int i = 0; i < N + 2; i++) {
for (int j = 0; j < N + 2; j++) {
maze[i][j] = new MazeCell(i, j);
}
}
// initialize border cells as already visited
for (int x = 0; x < N + 2; x++) {
maze[x][0].visited = true;
maze[x][N + 1].visited = true;
}
for (int y = 0; y < N + 2; y++) {
maze[0][y].visited = true;
maze[N + 1][y].visited = true;
}
}
// build the maze
private void buildMaze(int x, int y) {
maze[x][y].visited = true;
// while there is an unvisited neighbor
while (!maze[x][y + 1].visited || !maze[x + 1][y].visited
|| !maze[x][y - 1].visited || !maze[x - 1][y].visited) {
// pick random neighbor (could use Knuth's trick instead)
while (true) {
int r = rand.nextInt(4);
if (r == 0 && !maze[x][y + 1].visited) {
8. maze[x][y].nth = false;
maze[x][y + 1].sth = false;
buildMaze(x, y + 1);
break;
} else if (r == 1 && !maze[x + 1][y].visited) {
maze[x][y].est = false;
maze[x + 1][y].wst = false;
buildMaze(x + 1, y);
break;
} else if (r == 2 && !maze[x][y - 1].visited) {
maze[x][y].sth = false;
maze[x][y - 1].nth = false;
buildMaze(x, y - 1);
break;
} else if (r == 3 && !maze[x - 1][y].visited) {
maze[x][y].wst = false;
maze[x - 1][y].est = false;
buildMaze(x - 1, y);
break;
}
}
}
}
// build the maze starting from lower left
private void buildMaze() {
buildMaze(1, 1);
// Make sure visited is reset to false
for (int x = 1; x < N + 1; x++) {
for (int y = 1; y < N + 1; y++) {
maze[x][y].visited = false;
}
}
// delete some random walls
for (int i = 0; i < N; i++) {
int x = 1 + rand.nextInt(N - 1);
int y = 1 + rand.nextInt(N - 1);
9. maze[x][y].nth = maze[x][y + 1].sth = false;
}
}
// draw the initial maze
private void drawMaze() {
drawCircle(Color.RED, N / 2, N / 2, BIG);
drawCircle(Color.RED, 1, 1, BIG);
// Draw the walls in black
mf.setPenColor(Color.BLACK);
for (int x = 1; x <= N; x++) {
for (int y = 1; y <= N; y++) {
if (maze[x][y].sth) {
mf.line(x, y, x + 1, y);
}
if (maze[x][y].nth) {
mf.line(x, y + 1, x + 1, y + 1);
}
if (maze[x][y].wst) {
mf.line(x, y, x, y + 1);
}
if (maze[x][y].est) {
mf.line(x + 1, y, x + 1, y + 1);
}
}
}
delay(LONG);
}
private void delay(int t) {
// sleep until the next time we're allowed to draw
long millis = System.currentTimeMillis();
if (millis < nextDraw) {
try {
Thread.sleep(nextDraw - millis);
} catch (InterruptedException e) {
System.out.println("Error sleeping");
}
10. millis = nextDraw;
}
// when are we allowed to draw again
nextDraw = millis + t;
}
private void drawCircle(Color c, double x, double y, double size) {
mf.setFillColor(c);
mf.filledCircle(x + 0.5, y + 0.5, size);
}
public void findShortestPath() {
// Your code goes here!!!!!
}
}
class MazeCell {
// nth, sth, est, wst used to identify walls - true indicates wall present
boolean nth, sth, wst, est;
// used to indicate that a cell has already been processed
boolean visited;
// used to facilitate finding the neighbors of a cell
int row, col;
public MazeCell(int i, int j) {
row = i;
col = j;
// All walls are initially present for every cell
nth = sth = est = wst = true;
// Initially no cells have been visited
visited = false;
}
}
class MazeMap {
MazeCell nFromCenter = null;
MazeMap nMinus1FromCenter = null;
}
***end of code***
here is the stradgey that Im supposed to follow:
11. Strategy:
Implement the findShortestPath() method in the given code to find the shortest solution in the
maze.
Strategy will be using breadth first search starting from the end point of the maze looking for the
entrance.
Create two linked list of MazeMap objects
LinkedList
Create MazeMap for center and add to first list(Center MazeCell is maze[N/2][N/2], entrance is
maze[1][1])
Iterate through first list and add MazeMap distance n+1 to second list.
Set first list equal to second list, clear second list and repeat.
MazeCell:
In the GUI representation, rows of the maze are vertical, columns are horizontal. Cell 0,0 of the
maze in drawn in the lower left corner. The following summarizes what to do to move in a
specific direction from any cell in the maze. Remember, each cell contains its own row, col
position.
North neighbor is at row, col + 1
South neighbor is at row, col – 1
East neighbor is at row + 1, col
West neighbor is at row – 1, col
Solution
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.TextInputDialog;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class MazeApp extends Application
{
// default canvas size is DEFAULT_SIZE-by-DEFAULT_SIZE
private static final int DEFAULT_SIZE = 768;
12. private int width = DEFAULT_SIZE;
private int height = DEFAULT_SIZE;
// The graphics context is needed to enable drawing on the canvas
private GraphicsContext gc;
// boundary of drawing canvas, 0% border
// private static final double BORDER = 0.05;
private static final double BORDER = 0.00;
private double xmin, ymin, xmax, ymax;
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage primaryStage)
{
Group root = new Group();
Canvas canvas = new Canvas(width, height);
gc = canvas.getGraphicsContext2D();
gc.setLineWidth(2);
gc.setFill(Color.WHITE);
gc.fillRect(0, 0, width, height);
root.getChildren().add(canvas);
TextInputDialog tid = new TextInputDialog();
tid.setTitle("Maze Size");
tid.setHeaderText("Enter maze size between 10 and 50");
tid.showAndWait();
int size = Integer.parseInt(tid.getResult());
if (size > 50)
size = 50;
if (size < 10)
size = 10;
primaryStage.setTitle("Maze Application");
primaryStage.setScene(new Scene(root));
primaryStage.setResizable(false);
13. // Make sure that the application goes away when then window is closed
primaryStage.setOnCloseRequest(e -> System.exit(0));
primaryStage.show();
Maze maze = new Maze(this, size);
// Must solve the maze in a separate thread or else
// the GUI wont update until the end.....
Thread solver = new Thread(
new Runnable () {
public void run()
{
while(true)
{
maze.buildAndDrawMaze();
maze.findShortestPath();
try
{
Thread.sleep(5000);
}
catch(Exception e) { }
gc.setFill(Color.WHITE);
gc.fillRect(0, 0, width, height);
}
}
});
solver.start();
}
/**
* Sets the pen color to the specified color.
*
* @param color the color to make the pen
*/
public void setPenColor(Color color) {
gc.setStroke(color);
}
14. /**
* Sets the pen color to the specified color.
*
* @param color the color to make the pen
*/
public void setFillColor(Color color) {
gc.setFill(color);
}
/**
* Sets the x-scale to the specified range.
*
* @param min the minimum value of the x-scale
* @param max the maximum value of the x-scale
* @throws IllegalArgumentException if {@code (max == min)}
*/
public void setXscale(double min, double max) {
double size = max - min;
if (size == 0.0) {
throw new IllegalArgumentException("the min and max are the same");
}
xmin = min - BORDER * size;
xmax = max + BORDER * size;
}
/**
* Sets the y-scale to the specified range.
*
* @param min the minimum value of the y-scale
* @param max the maximum value of the y-scale
* @throws IllegalArgumentException if {@code (max == min)}
*/
public void setYscale(double min, double max) {
double size = max - min;
if (size == 0.0) {
throw new IllegalArgumentException("the min and max are the same");
}
ymin = min - BORDER * size;
15. ymax = max + BORDER * size;
}
// helper functions that scale from user coordinates to screen coordinates and back
private double scaleX(double x) {
return width * (x - xmin) / (xmax - xmin);
}
private double scaleY(double y) {
return height * (ymax - y) / (ymax - ymin);
}
private double factorX(double w) {
return w * width / Math.abs(xmax - xmin);
}
private double factorY(double h) {
return h * height / Math.abs(ymax - ymin);
}
private double userX(double x) {
return xmin + x * (xmax - xmin) / width;
}
private double userY(double y) {
return ymax - y * (ymax - ymin) / height;
}
/**
* Draws a line segment between (x0,
* y0) and (x1,
* y1).
*
* @param x0 the x-coordinate of one endpoint
* @param y0 the y-coordinate of one endpoint
* @param x1 the x-coordinate of the other endpoint
* @param y1 the y-coordinate of the other endpoint
*/
public void line(double x0, double y0, double x1, double y1) {
gc.strokeLine(scaleX(x0), scaleY(y0), scaleX(x1), scaleY(y1));
}
/**
* Draws one pixel at (x, y). This method is private
16. * because pixels depend on the display. To achieve the same effect, set the
* pen radius to 0 and call {@code point()}.
*
* @param x the x-coordinate of the pixel
* @param y the y-coordinate of the pixel
*/
private void pixel(double x, double y) {
gc.fillRect((int) Math.round(scaleX(x)), (int) Math.round(scaleY(y)), 1, 1);
}
/**
* Draws a filled circle of the specified radius, centered at (x,
* y).
*
* @param x the x-coordinate of the center of the circle
* @param y the y-coordinate of the center of the circle
* @param radius the radius of the circle
* @throws IllegalArgumentException if {@code radius} is negative
*/
public void filledCircle(double x, double y, double radius) {
double xs = scaleX(x);
double ys = scaleY(y);
double ws = factorX(2 * radius);
double hs = factorY(2 * radius);
if (ws <= 1 && hs <= 1) {
pixel(x, y);
} else {
gc.fillOval(xs - ws / 2, ys - hs / 2, ws, hs);
}
}
}
***********maze.java**************
package mazepackage;
import java.util.LinkedList;
import java.util.Random;
import javafx.scene.paint.Color;
public class Maze {
17. private int N; // dimension of maze
private MazeCell[][] maze;
private Random rand = new Random();
// Used to signal the maze has been solved
private boolean done;
// time in milliseconds (from currentTimeMillis()) when we can draw again
// used to control the frame rate
private long nextDraw = -1;
private MazeApp mf;
// Define constants for the circle size
private final double BIG = 0.375;
private final double SMALL = 0.25;
// Define constants for the delay times
private final int SHORT = 30;
private final int LONG = 500;
public Maze(MazeApp ma, int n) {
N = n;
mf = ma;
mf.setXscale(0, N + 2);
mf.setYscale(0, N + 2);
}
public void buildAndDrawMaze() {
createMaze();
buildMaze();
drawMaze();
}
// create the initial data structures that contain the maze data
private void createMaze() {
maze = new MazeCell[N + 2][N + 2];
for (int i = 0; i < N + 2; i++) {
for (int j = 0; j < N + 2; j++) {
maze[i][j] = new MazeCell(i, j);
}
}
// initialize border cells as already visited
for (int x = 0; x < N + 2; x++) {
18. maze[x][0].visited = true;
maze[x][N + 1].visited = true;
}
for (int y = 0; y < N + 2; y++) {
maze[0][y].visited = true;
maze[N + 1][y].visited = true;
}
}
// build the maze
private void buildMaze(int x, int y) {
maze[x][y].visited = true;
// while there is an unvisited neighbor
while (!maze[x][y + 1].visited || !maze[x + 1][y].visited
|| !maze[x][y - 1].visited || !maze[x - 1][y].visited) {
// pick random neighbor (could use Knuth's trick instead)
while (true) {
int r = rand.nextInt(4);
if (r == 0 && !maze[x][y + 1].visited) {
maze[x][y].nth = false;
maze[x][y + 1].sth = false;
buildMaze(x, y + 1);
break;
} else if (r == 1 && !maze[x + 1][y].visited) {
maze[x][y].est = false;
maze[x + 1][y].wst = false;
buildMaze(x + 1, y);
break;
} else if (r == 2 && !maze[x][y - 1].visited) {
maze[x][y].sth = false;
maze[x][y - 1].nth = false;
buildMaze(x, y - 1);
break;
} else if (r == 3 && !maze[x - 1][y].visited) {
maze[x][y].wst = false;
maze[x - 1][y].est = false;
buildMaze(x - 1, y);
19. break;
}
}
}
}
// build the maze starting from lower left
private void buildMaze() {
buildMaze(1, 1);
// Make sure visited is reset to false
for (int x = 1; x < N + 1; x++) {
for (int y = 1; y < N + 1; y++) {
maze[x][y].visited = false;
}
}
// delete some random walls
for (int i = 0; i < N; i++) {
int x = 1 + rand.nextInt(N - 1);
int y = 1 + rand.nextInt(N - 1);
maze[x][y].nth = maze[x][y + 1].sth = false;
}
}
// draw the initial maze
private void drawMaze() {
drawCircle(Color.RED, N / 2, N / 2, BIG);
drawCircle(Color.RED, 1, 1, BIG);
// Draw the walls in black
mf.setPenColor(Color.BLACK);
for (int x = 1; x <= N; x++) {
for (int y = 1; y <= N; y++) {
if (maze[x][y].sth) {
mf.line(x, y, x + 1, y);
}
if (maze[x][y].nth) {
mf.line(x, y + 1, x + 1, y + 1);
}
if (maze[x][y].wst) {
20. mf.line(x, y, x, y + 1);
}
if (maze[x][y].est) {
mf.line(x + 1, y, x + 1, y + 1);
}
}
}
delay(LONG);
}
private void delay(int t) {
// sleep until the next time we're allowed to draw
long millis = System.currentTimeMillis();
if (millis < nextDraw) {
try {
Thread.sleep(nextDraw - millis);
} catch (InterruptedException e) {
System.out.println("Error sleeping");
}
millis = nextDraw;
}
// when are we allowed to draw again
nextDraw = millis + t;
}
private void drawCircle(Color c, double x, double y, double size) {
mf.setFillColor(c);
mf.filledCircle(x + 0.5, y + 0.5, size);
}
public void findShortestPath() {
// Your code goes here!!!!!
}
}
class MazeCell {
// nth, sth, est, wst used to identify walls - true indicates wall present
boolean nth, sth, wst, est;
// used to indicate that a cell has already been processed
21. boolean visited;
// used to facilitate finding the neighbors of a cell
int row, col;
public MazeCell(int i, int j) {
row = i;
col = j;
// All walls are initially present for every cell
nth = sth = est = wst = true;
// Initially no cells have been visited
visited = false;
}
}
class MazeMap {
MazeCell nFromCenter = null;
MazeMap nMinus1FromCenter = null;
}