Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. Q1.
  2.  
  3. 1.) Declare a variable called ticketCost of type double .
  4.  
  5. 2.) Declare a variable called discount of type double .
  6.  
  7. 3.) Declare a variable called scanner of type Scanner
  8.  
  9. 4.) Create a new Scanner object to read from System.in
  10.  
  11. 5.) Assign the value of user input via the scanner to the variable ticketCost
  12.  
  13. 6.) Assign the value of the variable discount to be 50% of the ticket cost.
  14.  
  15. 7.) Print the following out to the console:
  16. (You must use the variable discount in the print statement , you should not attempt to format or modify the number of decimal places in the output to the console.)
  17.  
  18. The cost of three tickets is: [value of three discounted tickets]
  19.  
  20. Q2.
  21. 1.) Declare three variables of type 'double ' that are called:
  22.  
  23. lengthOfRoom
  24. widthOfRoom
  25. perimeter
  26. 2.) Assign 3.63 to the length
  27.  
  28. 3.) Assign 4.712 to the width
  29.  
  30. 4.) Use an expresssion to calculate the value of the perimeter
  31. (i.e. Multiply the length by 2, Multiply the width by 2 and add the results together)
  32.  
  33. 5.) Using the printf method ,to print out to the console:
  34. (You must use a format placeholder to ensure that only 1 decimal place is printed.)
  35.  
  36. The perimeter of your room is​: [the value of the perimeter]
  37.  
  38.  
  39. Q3.
  40. 1.) Declare a variable called scanner of type Scanner
  41.  
  42. 2.) Create a new Scanner object to read from System.in
  43.  
  44. 3.) Declare another variable called fullName of type String
  45.  
  46. 4.) Declare another variable called count of type Integer
  47.  
  48. 5.) Use the scanner variable to read a line of text and assign it to the variable fullName
  49.  
  50. 6.) Assign the value of count to the number of characters in the string stored in the fullName variable .
  51.  
  52. 7.) Print out to the console:
  53.  
  54. "My Full Name is [value of fullName] it has [value of count] characters ."
  55.  
  56. Q4.
  57. NOTE: You need only write the method . You do not need to write the class or any code to call or test the method .
  58.  
  59. 1.) Write a public method called findLastWord that takes a single parameter of type String and returns a String value to the caller of the method .
  60.  
  61. 2.) The body of the method should extract the last word from the String that is passed into the method and return that word to the caller of the method .
  62. (You can assume that the boundary or delimeter between words are defined by a single space.)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement