Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class Chapter4 {
- void exercise1() {
- Date myDateOne = new Date(84,0,29); //creates object
- Date myDateTwo = new Date(85,1,15);
- boolean x = myDateTwo.after(myDateOne);
- System.out.println(x);
- }
- void exercise2() {
- String myText = null; System.out.println("Please enter a word:"); BufferedReader x = new BufferedReader(new InputStreamReader(System.in)); try{
- myText = x.readLine(); }catch(IOException e){
- System.out.println("Error: " + e); }
- System.out.println(myText);
- }
- void exercise3() {
- String myGuess = null ;
- int points = 0 ;
- int overallpoints = 0 ;
- BufferedReader x = new BufferedReader(new InputStreamReader(System.in));
- System.out.println();
- System.out.print("What Year is it? ");
- System.out.println("A - 2015");
- System.out.println("B - 2016");
- System.out.println("C - 2017");
- System.out.println("Enter your answer:");
- try {
- myGuess = x.readLine();//read and place value into myGuess variable
- }catch(IOException e){
- System.out.println("Error: " );
- }
- if(myGuess.equals("A") || myGuess.equals("a")){ //selection to identify
- System.out.println(""); //variable value
- System.out.println("That is incorrect!");
- } else if(myGuess.equals("B") || myGuess.equals("b")){
- System.out.println("");
- System.out.println("That is incorrect!");
- } else if(myGuess.equals("C") || myGuess.equals("d")){
- System.out.println("");
- System.out.println("That is correct");
- points++ ;
- System.out.println();
- }
- String myGuess1 = null;
- BufferedReader xy = new BufferedReader(new InputStreamReader(System.in));
- System.out.println("When was the WWW created?");
- System.out.println("A - 1990");
- System.out.println("B - 1991");
- System.out.println("C - 1992");
- System.out.println("D - 1993");
- System.out.println("Enter your answer (letter):");
- try{
- myGuess = x.readLine();
- }catch(IOException e){
- System.out.println("Error: " + e);
- }
- if(myGuess.equals("A") || myGuess.equals("a")){
- System.out.println("");
- System.out.println("That is incorrect!");
- } else if(myGuess.equals("B") || myGuess.equals("b")){
- System.out.println("");
- System.out.println("That is correct!");
- } else if(myGuess.equals("C") || myGuess.equals("d")){
- System.out.println("");
- System.out.println("That is correct!");
- } else if(myGuess.equals("D") || myGuess.equals("d")){
- points++;
- System.out.println("");
- System.out.println("That is correct!");
- }
- //<-------Just repeat from here for each question
- System.out.println("Who invented the WWW?");
- System.out.println("A - Sir Tim Berners-Lee");
- System.out.println("B - Tim Berners-Lee");
- System.out.println("C – Bobby Bill Right");
- System.out.println("D – James May");
- System.out.println("Enter your answer (letter):");
- try{
- myGuess = x.readLine();
- }catch(IOException e){
- System.out.println("Error: " + e);
- }
- if(myGuess.equals("A") || myGuess.equals("a")){ //don’t forget to change
- System.out.println("");
- points++ ;
- //the answers
- System.out.println("That is correct!");
- } else if(myGuess.equals("B") || myGuess.equals("b")){
- System.out.println("");
- System.out.println("That is incorrect!");
- } else if(myGuess.equals("C") || myGuess.equals("d")){
- System.out.println("");
- System.out.println("That is incorrect!");
- } else if(myGuess.equals("D") || myGuess.equals("d")){
- System.out.println("");
- System.out.println("That is incorrect!");
- }
- System.out.println("When did England win the world cup?");
- System.out.println("A - 1966");
- points++ ;
- System.out.println("B - 1989");
- System.out.println("C – 1978");
- System.out.println("D – 1787");
- System.out.println("Enter your answer (letter):");
- try{
- myGuess = x.readLine();
- }catch(IOException e){
- System.out.println("Error: " + e);
- }
- if(myGuess.equals("A") || myGuess.equals("a")){ //don’t forget to change
- System.out.println("");
- ;//the answers
- System.out.println("That is correct!");
- } else if(myGuess.equals("B") || myGuess.equals("b")){
- System.out.println("");
- System.out.println("That is incorrect!");
- } else if(myGuess.equals("C") || myGuess.equals("d")){
- System.out.println("");
- System.out.println("That is incorrect!");
- } else if(myGuess.equals("D") || myGuess.equals("d")){
- System.out.println("");
- System.out.println("That is incorrect!");
- }
- System.out.println("Who is Niam Pabari");
- System.out.println("A - A student");
- System.out.println("B - A teacher");
- System.out.println("C – A master");
- System.out.println("D – A fighter");
- System.out.println("Enter your answer (letter):");
- try{
- myGuess = x.readLine();
- }catch(IOException e){
- System.out.println("Error: " + e);
- }
- if(myGuess.equals("A") || myGuess.equals("a")){ //don’t forget to change
- System.out.println("");
- points++ ;//the answers
- System.out.println("That is correct!");
- } else if(myGuess.equals("B") || myGuess.equals("b")){
- System.out.println("");
- System.out.println("That is incorrect!");
- } else if(myGuess.equals("C") || myGuess.equals("d")){
- System.out.println("");
- System.out.println("That is incorrect!");
- } else if(myGuess.equals("D") || myGuess.equals("d")){
- System.out.println("");
- System.out.println("That is incorrect!");
- }
- //<-------End of repeat
- System.out.println("Total points " + points ) ;
- }
- void question2() {
- String myGuess = null ;
- int points = 0 ;
- int overallpoints = 0 ;
- BufferedReader x = new BufferedReader(new InputStreamReader(System.in));
- System.out.println();
- System.out.print("What Month is it? ");
- System.out.println("A - Jan");
- System.out.println("B - Feb");
- System.out.println("C - Mar");
- System.out.println("Enter your answer:");
- try {
- myGuess = x.readLine();//read and place value into myGuess variable
- }catch(IOException e){
- System.out.println("Error: " );
- }
- if(myGuess.equals("A") || myGuess.equals("a")){ //selection to identify
- System.out.println(""); //variable value
- System.out.println("That is incorrect!");
- } else if(myGuess.equals("B") || myGuess.equals("b")){
- System.out.println("");
- System.out.println("That is incorrect!");
- } else if(myGuess.equals("C") || myGuess.equals("d")){
- System.out.println("");
- System.out.println("That is correct");
- System.out.println();
- }
- if (myGuess == "C") {
- overallpoints = points + 1 ;
- System.out.println("You have " + overallpoints + "points");
- }
- }
- void exercise5() {
- Scanner scanner = new Scanner(System.in);
- String username = null ;
- String Password = null ;
- System.out.println();
- System.out.print(" Username: ");
- username = scanner.next();
- System.out.println();
- System.out.print(" Password: ");
- Password = scanner.next();
- if (username.equals("admin") && Password.equals("letmein")) {
- System.out.println();
- System.out.print(" Access Granted");
- }
- else {
- System.out.println();
- System.out.println(" Access Denied");
- }
- }
- void exercise6 () {
- Scanner scanner = new Scanner(System.in);
- int Years ;
- int Points ;
- System.out.println();
- System.out.print("How many years have you been driving for?");
- Years = scanner.nextInt();
- System.out.println();
- System.out.print("How many points do you have?");
- Points = scanner.nextInt();
- if ((Years <=2 && Points >= 6) || (Years >=2 && Points >=12))
- {
- System.out.println();
- System.out.print("Your Licence is disqualifed!");
- }
- else {
- System.out.println();
- System.out.print("Your Licence is Safe!");
- }
- }
- void exercise7 () {
- Scanner scanner = new Scanner(System.in);
- double Number1 ;
- double Number2 ;
- double Sum ;
- String add , subtract , divide , multiply ;
- String Chosenoperation = null ;
- System.out.println();
- System.out.print("What would your first number to be?");
- Number1 = scanner.nextInt();
- System.out.println();
- System.out.print("What would you like your second number to be?");
- Number2 = scanner.nextInt();
- System.out.println();
- System.out.print("What Operation would you like to do to your numbers?");
- Chosenoperation = scanner.next();
- if (Chosenoperation.equals("add")) {
- System.out.println();
- System.out.print(Number1 + Number2);
- }
- if (Chosenoperation.equals("subtract")) {
- System.out.println();
- System.out.print(Number1 - Number2);
- }
- if (Chosenoperation.equals("divide")) {
- System.out.println();
- Sum = Number1 / Number2 ;
- System.out.print(Sum);
- }
- if (Chosenoperation.equals("multiply")) {
- System.out.println();
- System.out.print(Number1 * Number2);
- }
- }
- public Chapter4() {
- // TODO Auto-generated constructor stub
- exercise1();
- exercise2();
- exercise3();
- exercise5();
- exercise6();
- exercise7();
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Chapter4 attempt1 = new Chapter4();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement