Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Q1.
- 1.) Declare a variable called ticketCost of type double .
- 2.) Declare a variable called discount of type double .
- 3.) Declare a variable called scanner of type Scanner
- 4.) Create a new Scanner object to read from System.in
- 5.) Assign the value of user input via the scanner to the variable ticketCost
- 6.) Assign the value of the variable discount to be 50% of the ticket cost.
- 7.) Print the following out to the console:
- (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.)
- The cost of three tickets is: [value of three discounted tickets]
- Q2.
- 1.) Declare three variables of type 'double ' that are called:
- lengthOfRoom
- widthOfRoom
- perimeter
- 2.) Assign 3.63 to the length
- 3.) Assign 4.712 to the width
- 4.) Use an expresssion to calculate the value of the perimeter
- (i.e. Multiply the length by 2, Multiply the width by 2 and add the results together)
- 5.) Using the printf method ,to print out to the console:
- (You must use a format placeholder to ensure that only 1 decimal place is printed.)
- The perimeter of your room isβ: [the value of the perimeter]
- Q3.
- 1.) Declare a variable called scanner of type Scanner
- 2.) Create a new Scanner object to read from System.in
- 3.) Declare another variable called fullName of type String
- 4.) Declare another variable called count of type Integer
- 5.) Use the scanner variable to read a line of text and assign it to the variable fullName
- 6.) Assign the value of count to the number of characters in the string stored in the fullName variable .
- 7.) Print out to the console:
- "My Full Name is [value of fullName] it has [value of count] characters ."
- Q4.
- NOTE: You need only write the method . You do not need to write the class or any code to call or test the method .
- 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 .
- 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 .
- (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