Advertisement
Guest User

Untitled

a guest
Mar 31st, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.36 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6.  
  7. /**
  8. *
  9. * @author Noah
  10. */
  11. import javax.swing.*;
  12. import java.text.*;
  13. public class Main {
  14.  
  15. /**
  16. * @param args the command line arguments
  17. */
  18. public static void main(String[] args) {
  19. //Create username and password
  20. String userName = JOptionPane.showInputDialog("Create a username:","johndoe");
  21. String password = JOptionPane.showInputDialog("Create a password:","johndoe123");
  22. //Confirm username and password
  23. int dialogButton = JOptionPane.showConfirmDialog (null,"<html>Confirm your "
  24. + "information:<br>Username: " + userName + "<br>Password: " + password);
  25. if (dialogButton == 0){
  26. //Login or quit the program menu (Start-up menu)
  27. Object[] options = {"Login", "Quit"};
  28. int menuOption = JOptionPane.showOptionDialog(null, "Please choose the "
  29. + "program you would like to run:","Program Menu",JOptionPane.YES_NO_CANCEL_OPTION,
  30. JOptionPane.QUESTION_MESSAGE,null,options,options[1]);
  31. //Case options for the Switch Statement and Swtich statement itself
  32. switch (menuOption) {
  33.  
  34. case 0:
  35. //Login to account
  36. JTextField userNameConfirm = new JTextField();
  37. JTextField passwordConfirm = new JPasswordField();
  38. Object[] message = {
  39. "Username:", userNameConfirm,
  40. "Password:", passwordConfirm
  41. };
  42.  
  43. int option = JOptionPane.showConfirmDialog(null, message, "Login", JOptionPane.OK_CANCEL_OPTION);
  44. if (option == JOptionPane.OK_OPTION) {
  45. if (userNameConfirm.getText().equals(userName) && passwordConfirm.getText().equals(password)) {
  46. Object[] programOptions = {"Piggy Bank","Profile Analysis","Seasons"};
  47. int mainMenuOption = JOptionPane.showOptionDialog(null, "Please choose the "
  48. + "program you would like to run:","Program Menu",JOptionPane.YES_NO_CANCEL_OPTION,
  49. JOptionPane.QUESTION_MESSAGE,null,programOptions,programOptions[2]);
  50. switch (mainMenuOption) {
  51. case 0 : //Piggy Bank
  52. //Gets name and number of coins
  53. String personName = JOptionPane.showInputDialog("Enter your name: ","John");
  54. int quarters, dimes, nickels, pennies;
  55. quarters = Integer.parseInt(JOptionPane.showInputDialog(personName
  56. + ", Enter the"
  57. + ", number of quarters you have:"));
  58. dimes = Integer.parseInt(JOptionPane.showInputDialog(personName +
  59. ", Enter the number"
  60. + " of dimes:"));
  61. nickels = Integer.parseInt(JOptionPane.showInputDialog(personName
  62. + ", Enter the number"
  63. + " of nickels"));
  64. pennies = Integer.parseInt(JOptionPane.showInputDialog(personName
  65. + ", Enter the number"
  66. + " of pennies:"));
  67.  
  68. int weeksSaved = Integer.parseInt(JOptionPane.showInputDialog(personName +
  69. ", Enter the"
  70. + " number of weeks that you have been saving money:"));
  71. //Prints information of how many coins the user has
  72. System.out.println("Hello " + personName + ",");
  73. System.out.println("You have " + quarters + " quarters.");
  74. System.out.println("You have " + dimes + " dimes.");
  75. System.out.println("You have " + nickels + " nickels.");
  76. System.out.println("You have " + pennies + " pennies.");
  77. System.out.println("You have been saving for " + weeksSaved + " weeks.");
  78. //calculate out the amnt of money per coin and grand total as well as avgs
  79. double quarterWorth = quarters*.25;
  80. double dimeWorth = dimes*.10;
  81. double nickelWorth = nickels*.5;
  82. double penniesWorth = pennies*.01;
  83. double grandTotal = quarterWorth+dimeWorth+nickelWorth+penniesWorth;
  84. DecimalFormat cost = new DecimalFormat("00.00");
  85. double averageWeekWorth = grandTotal/weeksSaved;
  86. double yearlyWorth = averageWeekWorth*52;
  87. //Shows pop-ups declaring worth of each coin and how much the yearly avg will be
  88. JOptionPane.showMessageDialog(null, "<html>Your worth is currently:<br>"+
  89. "_________________" + "<br>" + quarters +" Quarters: $"
  90. + cost.format(quarterWorth) + "<br>" + dimes +" Dimes: $"
  91. + cost.format(dimeWorth) + "<br>" + nickels +" Nickels: $" +
  92. cost.format(nickelWorth) + "<br>" + pennies +" Pennies: $"
  93. + cost.format(penniesWorth)+"</htm>",
  94. "Piggy Bank",JOptionPane.PLAIN_MESSAGE);
  95. JOptionPane.showMessageDialog(null,"<html>The total of your piggy bank is: $"
  96. + cost.format(grandTotal) + "<br>Your average savings per week is: $"
  97. + cost.format(averageWeekWorth) + "<br>You average savings per year is: $"
  98. + cost.format(yearlyWorth) + "<br><br>Have a nice day!</htm>",
  99. "Piggy Bank",JOptionPane.PLAIN_MESSAGE);
  100. break; //end piggy bank
  101. case 1: //profile analysis
  102. String firstName = JOptionPane.showInputDialog("Enter your first name:");
  103. String lastName = JOptionPane.showInputDialog("Enter your last name");
  104. String streetAdress = JOptionPane.showInputDialog("Enter your street"
  105. + " address.","90 Apple Way");
  106. String city = JOptionPane.showInputDialog("Enter your city","Appleville");
  107. String zipCode = JOptionPane.showInputDialog("Enter your zip code",
  108. "11111");
  109. String state = JOptionPane.showInputDialog("Enter your state","New York");
  110. int confirmInfo =
  111. JOptionPane.showConfirmDialog(null, "Is this information correct: Name: "
  112. + firstName + " " + lastName + ", Address: " + streetAdress + " " + city
  113. + ", Zip Code:" + zipCode + ", State: " + state);
  114. if (confirmInfo == 0){
  115.  
  116. String birthday = JOptionPane.showInputDialog("Enter your birthday:",
  117. "MMDDYY");
  118. int confirmPassInfo = JOptionPane.showConfirmDialog(null,"Is this "
  119. + "information correct: First Name " + firstName + ", Last Name "
  120. + lastName + ", Birthday " + birthday);
  121. if (confirmPassInfo == 0) {
  122. String email = lastName + "@fakehhh.com";
  123. String passwordProfile = firstName.charAt(0) + firstName.charAt(1) +
  124. lastName.charAt(0) + lastName.charAt(1) + birthday;
  125. String name = firstName + " " + lastName;
  126. String birthdayDate ;
  127. birthdayDate = birthday.charAt(0) + birthday.charAt(1) + "/"
  128. + birthday.charAt(2) + birthday.charAt(3) + "/" + birthday.charAt(4)
  129. + birthday.charAt(5);
  130. String address = streetAdress + " " + city + " " + state +", "
  131. + zipCode;
  132. System.out.println("Here is your information.");
  133. System.out.println("Name: " + name);
  134. System.out.println("Birthday: " + birthdayDate);
  135. System.out.println("Address: " + address);
  136. System.out.println("Email: " + email);
  137. System.out.println("Password: " + passwordProfile);
  138.  
  139. } else {
  140. JOptionPane.showMessageDialog(null, "Please restart process", "ERROR",
  141. JOptionPane.ERROR_MESSAGE);
  142. }
  143. } else {
  144. JOptionPane.showMessageDialog(null, "Please restart process", "ERROR",
  145. JOptionPane.ERROR_MESSAGE);
  146. }
  147. break;//end of profile analysis
  148. case 2://Seasons
  149. int inputTemp = Integer.parseInt(JOptionPane.showInputDialog("Please input"
  150. + " the temperature:"));
  151. if (inputTemp > 90) {
  152. JOptionPane.showMessageDialog(null,"Based on the temperature, the "
  153. + "season is summer." );
  154.  
  155. } else if (inputTemp>70 && inputTemp<90) {
  156. JOptionPane.showMessageDialog(null,"Based on the temperature, the season"
  157. + " is spring.");
  158. } else if (inputTemp>50 && inputTemp<70){
  159. JOptionPane.showMessageDialog(null,"Based on the temperature, the season"
  160. + " is fall.");
  161. } else if (inputTemp<50) {
  162. JOptionPane.showMessageDialog(null,"Based on the temperature, the season"
  163. + " is winter");
  164. }
  165.  
  166. break;//end of seasons
  167. }
  168. } else { //If login is wrong
  169. JOptionPane.showMessageDialog(null,"Login Incorrect","Error"
  170. ,JOptionPane.ERROR_MESSAGE);
  171. System.exit(0);
  172. }
  173. }
  174. break;//end of program chooser
  175. case 1:
  176. System.exit(0);
  177. break;
  178. }
  179. } else {
  180. //If confirmation for username and password is false
  181. JOptionPane.showMessageDialog(null,"Please restart the process!","Error"
  182. ,JOptionPane.ERROR_MESSAGE);
  183. }
  184. }
  185.  
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement