Advertisement
willieshi232

Untitled

Oct 15th, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.94 KB | None | 0 0
  1. 5.import java.util.*;
  2. public class Project5
  3. {
  4. public static void main(String [] args)
  5. {
  6. Scanner pikachu = new Scanner(System.in);
  7. System.out.print("What is the distance between your two locations?");
  8. System.out.print("Input your first latitude");
  9. String degrees1 = pikachu.nextLine();
  10. double lat1 = Double.parseDouble(degrees1.substring(2));
  11. System.out.print("Input your first latitude minutes");
  12. double min1 = pikachu.nextDouble();
  13. if(degrees1.startsWith("S"))
  14. {
  15. lat1 = lat1*-1;
  16. min1 = min1*=1;
  17. }
  18. Scanner pikachu2 = new Scanner(System.in);
  19. System.out.print("Input your first longitude");
  20. String degrees2 = pikachu2.nextLine();
  21. double long1 = Double.parseDouble(degrees2.substring(2));
  22. System.out.print("Input your first longtitude minutes");
  23. double min2 = pikachu2.nextDouble();
  24. if(degrees2.startsWith("W"))
  25. {
  26. long1 = long1*-1;
  27. min2 = min2*-1;
  28. }
  29. Scanner pikachu3 = new Scanner(System.in);
  30. System.out.print("Input your second latitude");
  31. String degrees3 = pikachu3.nextLine();
  32. double lat2 = Double.parseDouble(degrees3.substring(2));
  33. System.out.print("Input your second latitude minutes");
  34. double min3 = pikachu3.nextDouble();
  35. if(degrees3.startsWith("S"))
  36. {
  37. lat2 = lat2*-1;
  38. min3 = min3*-1;
  39. }
  40. Scanner pikachu4 = new Scanner(System.in);
  41. System.out.print("Input your second longitude");
  42. String degrees4 = pikachu4.nextLine();
  43. double long2 = Double.parseDouble(degrees4.substring(2));
  44. System.out.print("Input your second longitude minutes");
  45. double min4 = pikachu.nextDouble();
  46. if(degrees4.startsWith("W"))
  47. {
  48. long2 = long2*-1;
  49. min4 = min4*-1;
  50. }
  51. double sphericaldiff = Calculation(lat1, min1, long1, min2, lat2, min3, long2, min4);
  52. System.out.println("Your spherical distance between location a and location b is"+sphericaldiff);
  53. }
  54. public static double Calculation(double lat1, double min1, double long1, double min2, double lat2, double min3, double long2, double min4)
  55. {
  56. double latitude1 = Math.toRadians(lat1+(min1/60));
  57. double longitude1 = Math.toRadians(long1+(min2/60));
  58. double latitude2 = Math.toRadians(lat2+(min3/60));
  59. double longitude2 = Math.toRadians(long2+(min4/60));
  60. double longdiff = longitude2-longitude1;
  61. double angulardistance = Math.acos(Math.sin(latitude1)*Math.sin(latitude2)+Math.cos(latitude1)*Math.cos(latitude2)*Math.cos(longdiff));
  62. double sphericaldiff = 6372.795*angulardistance;
  63. return sphericaldiff;
  64. }
  65. }
  66. 6.import java.util.*;
  67. public class Project6
  68. {
  69. public static void main(String [] args)
  70. {
  71. Scanner pikachu = new Scanner(System.in);
  72. System.out.println("!!!!!Its Calendar Time!!!!!");
  73. System.out.print("Input the amount of days in the month");
  74. double days = pikachu.nextInt();
  75. System.out.print("Input the first Sunday of the week");
  76. double sunday = pikachu.nextInt();
  77. int control = 0;
  78. System.out.println(" Sun Mon Tue Wed Thu Fri Sat ");
  79. System.out.println("+------+------+------+------+------+------+------+");
  80. if(sunday == 2)
  81. {
  82. for(int space = 1; space <=6; space++)
  83. {
  84. System.out.print("| ");
  85. control = 1;
  86. }
  87. }
  88. if(sunday == 3)
  89. {
  90. for(int space = 1; space <=5; space++)
  91. {
  92. System.out.print("| ");
  93. control = 2;
  94. }
  95. }
  96. if(sunday == 4)
  97. {
  98. for(int space = 1; space <=4; space++)
  99. {
  100. System.out.print("| ");
  101. control = 3;
  102. }
  103. }
  104. if(sunday == 5)
  105. {
  106. for(int space = 1; space <=3; space++)
  107. {
  108. System.out.print("| ");
  109. control = 4;
  110. }
  111. }
  112. if(sunday == 6)
  113. {
  114. for(int space = 1; space <=2; space++)
  115. {
  116. System.out.print("| ");
  117. control = 5;
  118. }
  119. }
  120. if(sunday == 7)
  121. {
  122. for(int space = 1; space <=1; space++)
  123. {
  124. System.out.print("| ");
  125. control = 6;
  126. }
  127. }
  128. for(int day = 1; day <= days; day++)
  129. {
  130. if(day <= 9)
  131. {
  132. System.out.print("| "+day+" ");
  133. }
  134. if(day >= 10)
  135. {
  136. System.out.print("| "+day+" ");
  137. }
  138. if(day == control || day == control+7 || day == control+14 || day == control+21 || day == control+28)
  139. {
  140. System.out.println("|");
  141. }
  142. }
  143. if(days == 31)
  144. {
  145. if(sunday == 1)
  146. {
  147. for(int blank = 1; blank<=4; blank++)
  148. {
  149. System.out.print(" |");
  150. }
  151. }
  152. if(sunday == 2)
  153. {
  154. for(int blank = 1; blank<=5; blank++)
  155. {
  156. System.out.print(" |");
  157. }
  158. }
  159. if(sunday == 3)
  160. {
  161. for(int blank = 1; blank<=6; blank++)
  162. {
  163. System.out.print(" |");
  164. }
  165. }
  166. if(sunday == 4)
  167. {
  168. for(int blank = 1; blank<=0; blank++)
  169. {
  170. System.out.print(" |");
  171. }
  172. }
  173. if(sunday == 5)
  174. {
  175. for(int blank = 1; blank<=1; blank++)
  176. {
  177. System.out.print(" |");
  178. }
  179. }
  180. if(sunday == 6)
  181. {
  182. for(int blank = 1; blank<=2; blank++)
  183. {
  184. System.out.print(" |");
  185. }
  186. }
  187. if(sunday == 7)
  188. {
  189. for(int blank = 1; blank<=3; blank++)
  190. {
  191. System.out.print(" |");
  192. }
  193. }
  194. }
  195. if(days == 30)
  196. {
  197. if(sunday == 1)
  198. {
  199. for(int blank = 1; blank<=5; blank++)
  200. {
  201. System.out.print(" |");
  202. }
  203. }
  204. if(sunday == 2)
  205. {
  206. for(int blank = 1; blank<=6; blank++)
  207. {
  208. System.out.print(" |");
  209. }
  210. }
  211. if(sunday == 3)
  212. {
  213. for(int blank = 1; blank<=0; blank++)
  214. {
  215. System.out.print(" |");
  216. }
  217. }
  218. if(sunday == 4)
  219. {
  220. for(int blank = 1; blank<=1; blank++)
  221. {
  222. System.out.print(" |");
  223. }
  224. }
  225. if(sunday == 5)
  226. {
  227. for(int blank = 1; blank<=2; blank++)
  228. {
  229. System.out.print(" |");
  230. }
  231. }
  232. if(sunday == 6)
  233. {
  234. for(int blank = 1; blank<=3; blank++)
  235. {
  236. System.out.print(" |");
  237. }
  238. }
  239. if(sunday == 7)
  240. {
  241. for(int blank = 1; blank<=4; blank++)
  242. {
  243. System.out.print(" |");
  244. }
  245. }
  246. }
  247. if(days == 29)
  248. {
  249. if(sunday == 1)
  250. {
  251. for(int blank = 1; blank<=6; blank++)
  252. {
  253. System.out.print(" |");
  254. }
  255. }
  256. if(sunday == 2)
  257. {
  258. for(int blank = 1; blank<=0; blank++)
  259. {
  260. System.out.print(" |");
  261. }
  262. }
  263. if(sunday == 3)
  264. {
  265. for(int blank = 1; blank<=1; blank++)
  266. {
  267. System.out.print(" |");
  268. }
  269. }
  270. if(sunday == 4)
  271. {
  272. for(int blank = 1; blank<=2; blank++)
  273. {
  274. System.out.print(" |");
  275. }
  276. }
  277. if(sunday == 5)
  278. {
  279. for(int blank = 1; blank<=3; blank++)
  280. {
  281. System.out.print(" |");
  282. }
  283. }
  284. if(sunday == 6)
  285. {
  286. for(int blank = 1; blank<=4; blank++)
  287. {
  288. System.out.print(" |");
  289. }
  290. }
  291. if(sunday == 7)
  292. {
  293. for(int blank = 1; blank<=5; blank++)
  294. {
  295. System.out.print(" |");
  296. }
  297. }
  298. }
  299. if(days == 28)
  300. {
  301. if(sunday == 1)
  302. {
  303. for(int blank = 1; blank<=0; blank++)
  304. {
  305. System.out.print(" |");
  306. }
  307. }
  308. if(sunday == 2)
  309. {
  310. for(int blank = 1; blank<=1; blank++)
  311. {
  312. System.out.print(" |");
  313. }
  314. }
  315. if(sunday == 3)
  316. {
  317. for(int blank = 1; blank<=2; blank++)
  318. {
  319. System.out.print(" |");
  320. }
  321. }
  322. if(sunday == 4)
  323. {
  324. for(int blank = 1; blank<=3; blank++)
  325. {
  326. System.out.print(" |");
  327. }
  328. }
  329. if(sunday == 5)
  330. {
  331. for(int blank = 1; blank<=4; blank++)
  332. {
  333. System.out.print(" |");
  334. }
  335. }
  336. if(sunday == 6)
  337. {
  338. for(int blank = 1; blank<=5; blank++)
  339. {
  340. System.out.print(" |");
  341. }
  342. }
  343. if(sunday == 7)
  344. {
  345. for(int blank = 1; blank<=6; blank++)
  346. {
  347. System.out.print(" |");
  348. }
  349. }
  350. }
  351. System.out.println("|");
  352. System.out.print("+------+------+------+------+------+------+------+");
  353. }
  354. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement