Question: 13: caughtSpeeding Write a function in Java that implements the following logic: You are driving a little too fast, and a police officer stops you.
13: caughtSpeeding
Write a function in Java that implements the following logic: You are driving a little too fast, and a police officer stops you. Write code to compute the result, encoded as an int value: 0=no ticket, 1=small ticket, or 2=big ticket. If speed is 60 or less, the result is 0. If speed is between 61 and 80 inclusive, the result is 1. If speed is 81 or more, the result is 2. Unless it is your birthday--on that day, your speed can be 5 higher in all cases.
public int caughtSpeeding(int speed, boolean isBirthday)
{
}
19: makeBricks
Write a function in Java to implement the following logic: We want to make a row of bricks that is goal inches long. We have a number of small bricks (1 inch each) and big bricks (5 inches each). Return true if it is possible to make the goal by choosing from the given bricks. This is a little harder than it looks and can be done without any loops (hint: use the mod operator %).
public boolean makeBricks(int small, int big, int goal)
{
}
22: noTeenSum
Write two methods in Java that implements the following logic: Given 3 int values, a, b, and c, return their sum. However, if any of the values is a teen--in the range 13..19 inclusive--then that value counts as 0, except 15 and 16 do not count as teens. Write a separate helper method called fixTeen() that takes in an int value and returns that value fixed for the teen rule. In this way you avoid repeating the teen code 3 times (i.e. "decomposition").
public int noTeenSum(int a, int b, int c)
{
}
public int fixTeen(int n)
{
}
25: evenlySpaced
Write a function in Java that implements the following logic: Given three ints, a, b, and c, one of them is small, one is medium and one is large. Return true if the three values are evenly spaced, so the difference between small and medium is the same as the difference between medium and large.
public boolean evenlySpaced(int a, int b, int c)
{
}
26: atFirst
Write a function in Java that implements the following logic: Given a string, return a string made of its first 2 chars. If the string length is less than 2, use '@' for the missing chars.
public String atFirst(String str)
{
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
