Question
Q4: (Count the letters in a string) Write a method that counts the number of letters in a string using the following header: public static
Q4: (Count the letters in a string) Write a method that counts the number of letters in a string using the following header: public static int countLetters(String s) Write a test program that prompts the user to enter a string and displays the number of letters in the string
. Q5: (Multiples) Write a method isMultiple that determines, for a pair of integers, whether the second integer is a multiple of the first. The method should take two integer arguments and return true if the second is a multiple of the first and false otherwise. Incorporate this method in a java program that inputs a series of pairs of integers (one pair at a time) and determines whether the second value in each pair is a multiple of the first.
Q6: (Display matrix of 0s and 1s) Write a method that displays an n-by-n matrix using the following header:
public static void printMatrix(int n)
Each element is 0 or 1, which is generated randomly. Write a test program that prompts the user to enter n and displays an n-by-n matrix.
Here is a sample run:
Enter n: 3
0 1 0
0 0 0
1 1 1
Q7: (Parking Charge) A parking garage charges a RM 2.00 minimum fee to park for up to three hours. The garage charges an additional RM 0.50 per hour for each subsequent hour. The maximum charge for any given 24-hour period is RM 10.00. Assume that no car parks for longer than 24 hours at a time. Write a java program that calculates and displays the parking charges for each customer who parked in the garage yesterday. You should enter the hours parked for each customer. The program should display the charge for the current customer and should calculate and display the running total of yesterdays receipts. It should use the method calculateCharges to determine the charge for each customer.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started