Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author Noah
- */
- import javax.swing.*;
- import java.text.*;
- public class Main {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- //Create username and password
- String userName = JOptionPane.showInputDialog("Create a username:","johndoe");
- String password = JOptionPane.showInputDialog("Create a password:","johndoe123");
- //Confirm username and password
- int dialogButton = JOptionPane.showConfirmDialog (null,"<html>Confirm your "
- + "information:<br>Username: " + userName + "<br>Password: " + password);
- if (dialogButton == 0){
- //Login or quit the program menu (Start-up menu)
- Object[] options = {"Login", "Quit"};
- int menuOption = JOptionPane.showOptionDialog(null, "Please choose the "
- + "program you would like to run:","Program Menu",JOptionPane.YES_NO_CANCEL_OPTION,
- JOptionPane.QUESTION_MESSAGE,null,options,options[1]);
- //Case options for the Switch Statement and Swtich statement itself
- switch (menuOption) {
- case 0:
- //Login to account
- JTextField userNameConfirm = new JTextField();
- JTextField passwordConfirm = new JPasswordField();
- Object[] message = {
- "Username:", userNameConfirm,
- "Password:", passwordConfirm
- };
- int option = JOptionPane.showConfirmDialog(null, message, "Login", JOptionPane.OK_CANCEL_OPTION);
- if (option == JOptionPane.OK_OPTION) {
- if (userNameConfirm.getText().equals(userName) && passwordConfirm.getText().equals(password)) {
- Object[] programOptions = {"Piggy Bank","Profile Analysis","Seasons"};
- int mainMenuOption = JOptionPane.showOptionDialog(null, "Please choose the "
- + "program you would like to run:","Program Menu",JOptionPane.YES_NO_CANCEL_OPTION,
- JOptionPane.QUESTION_MESSAGE,null,programOptions,programOptions[2]);
- switch (mainMenuOption) {
- case 0 : //Piggy Bank
- //Gets name and number of coins
- String personName = JOptionPane.showInputDialog("Enter your name: ","John");
- int quarters, dimes, nickels, pennies;
- quarters = Integer.parseInt(JOptionPane.showInputDialog(personName
- + ", Enter the"
- + ", number of quarters you have:"));
- dimes = Integer.parseInt(JOptionPane.showInputDialog(personName +
- ", Enter the number"
- + " of dimes:"));
- nickels = Integer.parseInt(JOptionPane.showInputDialog(personName
- + ", Enter the number"
- + " of nickels"));
- pennies = Integer.parseInt(JOptionPane.showInputDialog(personName
- + ", Enter the number"
- + " of pennies:"));
- int weeksSaved = Integer.parseInt(JOptionPane.showInputDialog(personName +
- ", Enter the"
- + " number of weeks that you have been saving money:"));
- //Prints information of how many coins the user has
- System.out.println("Hello " + personName + ",");
- System.out.println("You have " + quarters + " quarters.");
- System.out.println("You have " + dimes + " dimes.");
- System.out.println("You have " + nickels + " nickels.");
- System.out.println("You have " + pennies + " pennies.");
- System.out.println("You have been saving for " + weeksSaved + " weeks.");
- //calculate out the amnt of money per coin and grand total as well as avgs
- double quarterWorth = quarters*.25;
- double dimeWorth = dimes*.10;
- double nickelWorth = nickels*.5;
- double penniesWorth = pennies*.01;
- double grandTotal = quarterWorth+dimeWorth+nickelWorth+penniesWorth;
- DecimalFormat cost = new DecimalFormat("00.00");
- double averageWeekWorth = grandTotal/weeksSaved;
- double yearlyWorth = averageWeekWorth*52;
- //Shows pop-ups declaring worth of each coin and how much the yearly avg will be
- JOptionPane.showMessageDialog(null, "<html>Your worth is currently:<br>"+
- "_________________" + "<br>" + quarters +" Quarters: $"
- + cost.format(quarterWorth) + "<br>" + dimes +" Dimes: $"
- + cost.format(dimeWorth) + "<br>" + nickels +" Nickels: $" +
- cost.format(nickelWorth) + "<br>" + pennies +" Pennies: $"
- + cost.format(penniesWorth)+"</htm>",
- "Piggy Bank",JOptionPane.PLAIN_MESSAGE);
- JOptionPane.showMessageDialog(null,"<html>The total of your piggy bank is: $"
- + cost.format(grandTotal) + "<br>Your average savings per week is: $"
- + cost.format(averageWeekWorth) + "<br>You average savings per year is: $"
- + cost.format(yearlyWorth) + "<br><br>Have a nice day!</htm>",
- "Piggy Bank",JOptionPane.PLAIN_MESSAGE);
- break; //end piggy bank
- case 1: //profile analysis
- String firstName = JOptionPane.showInputDialog("Enter your first name:");
- String lastName = JOptionPane.showInputDialog("Enter your last name");
- String streetAdress = JOptionPane.showInputDialog("Enter your street"
- + " address.","90 Apple Way");
- String city = JOptionPane.showInputDialog("Enter your city","Appleville");
- String zipCode = JOptionPane.showInputDialog("Enter your zip code",
- "11111");
- String state = JOptionPane.showInputDialog("Enter your state","New York");
- int confirmInfo =
- JOptionPane.showConfirmDialog(null, "Is this information correct: Name: "
- + firstName + " " + lastName + ", Address: " + streetAdress + " " + city
- + ", Zip Code:" + zipCode + ", State: " + state);
- if (confirmInfo == 0){
- String birthday = JOptionPane.showInputDialog("Enter your birthday:",
- "MMDDYY");
- int confirmPassInfo = JOptionPane.showConfirmDialog(null,"Is this "
- + "information correct: First Name " + firstName + ", Last Name "
- + lastName + ", Birthday " + birthday);
- if (confirmPassInfo == 0) {
- String email = lastName + "@fakehhh.com";
- String passwordProfile = firstName.charAt(0) + firstName.charAt(1) +
- lastName.charAt(0) + lastName.charAt(1) + birthday;
- String name = firstName + " " + lastName;
- String birthdayDate ;
- birthdayDate = birthday.charAt(0) + birthday.charAt(1) + "/"
- + birthday.charAt(2) + birthday.charAt(3) + "/" + birthday.charAt(4)
- + birthday.charAt(5);
- String address = streetAdress + " " + city + " " + state +", "
- + zipCode;
- System.out.println("Here is your information.");
- System.out.println("Name: " + name);
- System.out.println("Birthday: " + birthdayDate);
- System.out.println("Address: " + address);
- System.out.println("Email: " + email);
- System.out.println("Password: " + passwordProfile);
- } else {
- JOptionPane.showMessageDialog(null, "Please restart process", "ERROR",
- JOptionPane.ERROR_MESSAGE);
- }
- } else {
- JOptionPane.showMessageDialog(null, "Please restart process", "ERROR",
- JOptionPane.ERROR_MESSAGE);
- }
- break;//end of profile analysis
- case 2://Seasons
- int inputTemp = Integer.parseInt(JOptionPane.showInputDialog("Please input"
- + " the temperature:"));
- if (inputTemp > 90) {
- JOptionPane.showMessageDialog(null,"Based on the temperature, the "
- + "season is summer." );
- } else if (inputTemp>70 && inputTemp<90) {
- JOptionPane.showMessageDialog(null,"Based on the temperature, the season"
- + " is spring.");
- } else if (inputTemp>50 && inputTemp<70){
- JOptionPane.showMessageDialog(null,"Based on the temperature, the season"
- + " is fall.");
- } else if (inputTemp<50) {
- JOptionPane.showMessageDialog(null,"Based on the temperature, the season"
- + " is winter");
- }
- break;//end of seasons
- }
- } else { //If login is wrong
- JOptionPane.showMessageDialog(null,"Login Incorrect","Error"
- ,JOptionPane.ERROR_MESSAGE);
- System.exit(0);
- }
- }
- break;//end of program chooser
- case 1:
- System.exit(0);
- break;
- }
- } else {
- //If confirmation for username and password is false
- JOptionPane.showMessageDialog(null,"Please restart the process!","Error"
- ,JOptionPane.ERROR_MESSAGE);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement