Advertisement
Vendrick-Xander

4 hw programs

Jan 16th, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. Program that determines type of website:
  2. package com.Suarez;
  3. /*
  4. Xander fermier
  5. 1/16/19
  6. the user inputs a url and based on the last four characters the computer determines what type of address it is
  7. */
  8.  
  9.  
  10.  
  11. import java.util.*;
  12.  
  13. public class TypeOfWebsite {
  14. public static void main(String[] args)
  15. {
  16. System.out.println("Enter a website");
  17. Scanner web = new Scanner(System.in);
  18. String url = web.nextLine();
  19. int webLength = url.length();
  20. String webType = url.substring(webLength-4);
  21. switch (webType)
  22. {
  23. case ".gov":
  24. System.out.println("It is a government web address.");
  25. break;
  26. case ".edu":
  27. System.out.println("It is a university web address");
  28. break;
  29. case ".com":
  30. System.out.println("It is a business web address");
  31. break;
  32. case ".org":
  33. System.out.println("It is an organization web address");
  34. break;
  35. default:
  36. System.out.println("It is a web address for another entity");
  37. break;
  38. }
  39. }
  40. }
  41.  
  42. Program that gives likely season:
  43. package com.Suarez;
  44. /*
  45. xander fermier
  46. 1/16/19
  47. the user inputs a range and based on the range the computer will output the likely season
  48. */
  49.  
  50.  
  51.  
  52. import java.util.*;
  53.  
  54. public class temperatureRangeGuess {
  55. public static void main(String []args)
  56. {
  57. System.out.println("Give me a temperature and I will predict the season.");
  58. Scanner tempInput = new Scanner(System.in);
  59. int temp = tempInput.nextInt();
  60.  
  61. if (temp > 90 && temp < 110)
  62. {
  63. System.out.println("The season is probably summer.");
  64. }
  65. else if (temp >= 70 && temp < 90)
  66. {
  67. System.out.println("The season is probably spring.");
  68. }
  69. else if (temp >= 50 && temp < 70)
  70. {
  71. System.out.println("The season is probably autumn.");
  72. }
  73. else if (temp <50 && temp >-5)
  74. {
  75. System.out.println("The season is probably winter.");
  76. }
  77. else
  78. {
  79. System.out.println("The temperature you entered is outside the valid range.");
  80. }
  81. }
  82. }
  83.  
  84. Program that outputs a year:
  85. package com.Suarez;
  86. /*
  87. Xander fermier
  88. 1/16/19
  89. the user inputs either two or four numbers and the computer will output that as a year
  90. */
  91.  
  92.  
  93.  
  94. import java.util.*;
  95.  
  96. public class YearOutput {
  97. public static void main( String [] args)
  98. {
  99. System.out.println("Give me a year");
  100. Scanner yearInput = new Scanner(System.in);
  101. String yearString = yearInput.next();
  102. int yearInt = Integer.parseInt(yearString);
  103. int yearLength = yearString.length();
  104. if (yearLength == 2)
  105. {
  106. System.out.println("The year is " + (yearInt + 2000));
  107. }
  108. else if(yearLength == 4)
  109. {
  110. System.out.println("The year is " + yearInt);
  111. }
  112. else
  113. {
  114. System.out.println("That is not a valid year.");
  115. }
  116. }
  117. }
  118.  
  119. program that checks username and password:
  120. package com.Suarez;
  121. /*
  122. Xander Fermier
  123. 1/16/19
  124. the code takes a username and password from the user and then will grant or deny access depending on what they enter and tell them which filed did not match
  125. */
  126.  
  127.  
  128. import java.util.*;
  129.  
  130.  
  131. public class UsernameAndPasswordCheck {
  132. public static void main(String[] args)
  133. {
  134. System.out.println("Please enter your username.");
  135. Scanner input = new Scanner(System.in);
  136. String username = input.next();
  137. System.out.println("Enter your password");
  138. String password = input.next();
  139. if (username.equals("admin") && password.equals("open"))
  140. {
  141. System.out.println("Welcome.");
  142. }
  143. else if (username.equals("admin") && !password.equals("open"))
  144. {
  145. System.out.println("Wrong password.");
  146. }
  147. else if (!username.equals("admin") && password.equals("open"))
  148. {
  149. System.out.println("Wrong username.");
  150. }
  151. else
  152. {
  153. System.out.println("Sorry, wrong username and password.");
  154. }
  155. }
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement