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.
Java Question help needed In the program Fill the Add statements.pdf
1. Java Question : help needed In the program "Fill the Add statements Area" here area. Sample
Output in the picture
Consider a maze made up of a rectangular array of squares. The maze will contain a
character (either +, -, or |) to represent a blocked square, and to form the walls of the
maze. Mazes will have only one entrance at the Coordinate (0, 1), with only one exit in
the lower right hand corner of the maze.
Beginning at the entrance to the maze, find a path to the exit at the bottom right of the
maze. You may only move up, down, left, and right. Each square in the maze can be in
one of four states: clear (space), blocked (X), path (.), or visited (*). Initially, after the
maze has been read in from the file, each square will be either clear or blocked. If a
square lies on a successful path, mark it with a period. If you visit a square but it does
not lead to a successful path, mark it as visited with an asterisk.
This is the program for it
public class Coordinate {
public int x;
public int y;
public Coordinate( int x, int y ) {
this.x = x;
this.y = y;
}
public String toString() {
return "(" + this.x + "," + this.y + ")";
}
@Override
public boolean equals( Object object ) {
if( object == null ) {
return false;
}
if( ! Coordinate.class.isAssignableFrom( object.getClass() )) {
return false;
}
final Coordinate other = (Coordinate) object;
return this.x == other.x && this.y == other.y;
}
}
2. import java.util.Vector;
public class Maze {
private char[][] maze;
private int height;
private int width;
/**
* Create a new Maze of the specified height and width, initializing every
* location as empty, with a ' '.
**/
public Maze( int width, int height ) {
this.width = width;
this.height = height;
this.maze = new char [this.width][this.height];
// ADD STATEMENTS HERE
}
/**
* Mutator to allow us to set the specified Coordinate as blocked,
* marking it with a 'X'
**/
public void setBlocked( Coordinate coord ) {
// ADD STATEMENTS HERE
}
/**
* Mutator to allow us to set the specified Coordinate as having been visited,
* marking it with a '*'
**/
public void setVisited( Coordinate coord ) {
// ADD STATEMENTS HERE
}
/**
* Mutator to allow us to set the specified Coordinate as part of the path solution,
* marking it with a '.'
**/
public void setPath( Coordinate coord ) {
// ADD STATEMENTS HERE
3. }
/**
* Returns the character at the locatio specified by the Coordinate
**/
public char at( Coordinate coord ) {
// ADD STATEMENTS HERE
}
/**
* Returns a Coordinate array containing all Coordinates that are clear around
* the specified coordinate.
**/
public Coordinate[] clearAround( Coordinate coord ) {
Vector vector = new Vector();
// ADD STATEMENTS HERE
// Look at each of the locations around the specified Coordinate, and add it
// to the vector if it is clear (i.e. a space)
return vector.toArray( new Coordinate[0] );
}
/**
* Returns a Coordinate that provides the entrance location in this maze.
**/
public Coordinate start() {
return new Coordinate( 0, 1 );
}
/**
* Returns a Coordinate that provides the exit location from this maze.
**/
public Coordinate end() {
// ADD STATEMENTS HERE
}
/**
* The toString() method is responsible for creating a String representation
* of the Maze. See the project specification for sample output. Note that
* the String representation adds numbers across the top and side of the Maze
4. * to show the Coordinates of each cell in the maze.
**/
public String toString() {
StringBuilder buffer = new StringBuilder();
// ADD STATEMENTS HERE
// First, print out the column headings
// Next, print out each row in the maze - note the spaces between
// cells to facilitate reading. Each row should include its row number.
for(int x=0; x
for(int y=0; y
buffer.append(maze[x][y]);
buffer.append(" ");
return buffer.toString();
}
}
package p2;
import java.io.FileNotFoundException;
public class MazeSolver {
private Maze maze;
private LinkedStack path;
public MazeSolver( Maze maze ) {
// ADD STATEMENTS HERE
}
public void solve() {
// ADD STATEMENTS HERE
// Add the starting Coordinate to the maze, and while the Stack has
// entries, and the top of the Stack is not the end, continue searching
// for the path
}
public static void main( String[] args ) throws FileNotFoundException {
MazeReader reader = new MazeReader( "sampleMaze.txt" );
Maze maze = reader.open();
MazeSolver solver = new MazeSolver( maze );
5. System.out.println( "Before solving" );
System.out.println( maze );
System.out.println( "Start is " + maze.start() );
System.out.println( "End is " + maze.end() );
solver.solve();
System.out.println( "After solving (. shows solution, o shows visited)" );
System.out.println( maze );
}
}package p2;import java.util.Scanner;import java.io.File;import
java.io.FileNotFoundException;public class MazeReader {private String fileName;private Maze
maze;public MazeReader( String fileName ) {this.fileName = fileName;this.maze = null;}public
Maze open() throws FileNotFoundException {Scanner scanner = new Scanner( new File(
this.fileName ));int width = scanner.nextInt();int height = scanner.nextInt();this.maze = new
Maze( width, height );// Remove new line after intscanner.nextLine();// ADD STATEMENTS
HERE// You will need to read in each line using the Scanner, and provide// the row number and
the line to the addLine method to add it to the Mazereturn this.maze;}private void addLine( int
row, String line ) {// ADD STATEMENTS HERE}public static void main( String[] args )
throws FileNotFoundException {MazeReader reader = new MazeReader( "sampleMaze.txt"
);Maze maze = reader.open();System.out.println( maze );System.out.println( maze.at( new
Coordinate( 0, 0 )));System.out.println( maze.at( new Coordinate( 0, 1 )));}}
Solution
import java.io.*;
class Maze
{
class MazeSquare
{
public boolean hasTopWall;
public boolean hasRightWall;
public boolean hasLeftWall;
public boolean hasBottomWall;
public MazeSquare()
{
hasTopWall = hasRightWall = hasLeftWall = hasBottomWall = false;
6. }
}
class MazeFormatException extends Exception
{
public final static int noError = 0;
public final static int badRowAndColumnCounts = 1;
public final static int wrongNumberOfEntriesInRow = 2;
public final static int badEntry = 3;
public int lineNumber;
public int problem;
public MazeFormatException( int line, int prob )
{
lineNumber = line;
problem = prob;
}
}
private int nRows;
private int nColumns;
MazeSquare[][] square;
public static void main( String[] args )
{
if( args.length != 1 )
{
System.err.println( "Usage: java Maze mazeFileName" );
System.exit( 1 );
}
Maze knosos = null;
try
{
knosos = new Maze( args[0] );
}
catch( FileNotFoundException e )
{
System.err.println( "Can't open " + args[0] + ". Check your spelling." );
System.exit( 1 );
}
7. catch( IOException e )
{
System.err.println( "Severe input error. I give up." );
System.exit( 1 );
}
catch( MazeFormatException e )
{
switch( e.problem )
{
case MazeFormatException.badRowAndColumnCounts:
System.err.println( args[0] + ", line " + e.lineNumber + ": row and column counts
expected" );
break;
case MazeFormatException.wrongNumberOfEntriesInRow:
System.err.println( args[0] + ", line " + e.lineNumber + ": wrong number of entries"
);
break;
case MazeFormatException.badEntry:
System.err.println( args[0] + ", line " + e.lineNumber + ": non-hexadecimal digit
detected" );
break;
default:
System.err.println( "This should never get printed." );
break;
}
System.exit( 1 );
}
knosos.print( System.out );
}
public Maze()
{
square = null;
nRows = nColumns = 0;
}
public Maze( String fileName ) throws FileNotFoundException, IOException,
MazeFormatException
8. {
BufferedReader in = null;
in = new BufferedReader( new FileReader( fileName ) );
load( in );
in.close();
}
public void load( BufferedReader in ) throws MazeFormatException
{
String line;
String[] tokens;
int lineNumber = 0;
try
{
line = in.readLine();
lineNumber++;
tokens = line.split( "s+" );
nRows = Integer.parseInt( tokens[0] );
nColumns = Integer.parseInt( tokens[1] );
if( nRows <= 0 || nColumns <= 0 )
throw new Exception();
}
catch( Exception e )
{
throw new MazeFormatException( lineNumber,
MazeFormatException.badRowAndColumnCounts );
}
// Allocate the 2D array of MazeSquares.
square = new MazeSquare[nRows][nColumns];
for( int i=0; i < nRows; i++ )
for( int j=0; j < nColumns; j++ )
square[i][j] = new MazeSquare();
for( int i=0; i < nRows; i++ )
{
try
{
line = in.readLine();
9. lineNumber++;
tokens = line.split( "s+" );
if( tokens.length != nColumns )
throw new Exception();
}
catch( Exception e )
{
throw new MazeFormatException( lineNumber,
MazeFormatException.wrongNumberOfEntriesInRow );
}
for( int j=0; j < nColumns; j++ )
{
int squareValue;
try
{
squareValue = Integer.parseInt( tokens[j], 16 );
}
catch( NumberFormatException e )
{
throw new MazeFormatException( lineNumber, MazeFormatException.badEntry );
}
// These are "bitwise AND" operations. We'll discuss them in class.
square[i][j].hasTopWall = ((squareValue & 1) != 0);
square[i][j].hasRightWall = ((squareValue & 2) != 0);
square[i][j].hasBottomWall = ((squareValue & 4) != 0);
square[i][j].hasLeftWall = ((squareValue & 8) != 0);
}
}
}
public void print( PrintStream out )
{
int i, j;
for( i=0; i < nRows; i++ )
{
out.print( '+' );