Project2.txt - /Project 2 import java.util.Scanner import...

This preview shows page 1 - 2 out of 4 pages.

//Project 2 import java.util.Scanner; import java.text.SimpleDateFormat; import java.util.Date; public class ShapeMachine { static Scanner input = new Scanner(System.in); public static void main(String args[]) { System.out.println("Shape Machine login"); System.out.println(""); login(); } // This method grants access to the "Shape Machine" once the correct // password is inputted. public static void login() { // Retrieves today's date as a String and converts it to an int Date curDate = new Date(); SimpleDateFormat format = new SimpleDateFormat(); String DateToStr = format.format(curDate); format = new SimpleDateFormat("yyyy/MM/dd"); DateToStr = format.format(curDate); String stringDay = DateToStr.substring(8); String stringMonth = DateToStr.substring(5, 7); String stringYear = DateToStr.substring(0, 4); int day = Integer.parseInt(stringDay); int month = Integer.parseInt(stringMonth); int year = Integer.parseInt(stringYear); // Increments the number of login attempts and checks to see if the // user's input matches today's date // If 3 incorrect attempts are performed, the program terminates // If correct password is entered, the Shape machine calculator method // is called for (int loginAttempt = 1; loginAttempt < 4; loginAttempt++) { // Asks for user's input System.out.print("What is today's day? "); int dayInput = input.nextInt(); System.out.print("What is today's month? "); int monthInput = input.nextInt(); System.out.print("What is today's year? "); int yearInput = input.nextInt(); //Iterates through user's response and compares to today's date if (dayInput != day || monthInput != month || yearInput != year) { if (loginAttempt == 3) { System.out.println("#ERROR 3rd invalid login

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture