1/5
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Library to import for user input
import java.util.Scanner;
Code to get user input for name
Scanner scan = new Scanner(System.in)
System.out.println("Enter your name: ");
theName = scan.nextLine();
.next() vs .nextLine()
next reads until space
nextLine reads until \n
Important note about .next()
.next leaves \n in buffer
so…
System.out.print("Enter age: ");
int age = sc.nextInt();
System.out.print("Enter name: ");
String name = sc.nextLine(); // This may be skipped
Code to establish an abtract Piece class with an abtract move method
abtract public class ChessPiece{
// Stuff goes in here
abtract public void move();
}
Code to extend the ChessPiece class with a Queen class (Add constructor and move)
public class Queen extends ChessPiece {
public Queen(int row, int col)
super(row,col)
@Override
public void move() {
// Stuff here
}
}