Program #1 Program Description : Many cities levy traffic fines based on a flat
ID: 3788808 • Letter: P
Question
Program #1
Program Description: Many cities levy traffic fines based on a flat rate and a per dollar charge for each mile over the speed limit the vehicle was travelling. Write a program that determines the fine based on the following:
A charge of $20.00 for the ticket.
An additional charge of $5.00 for each mile over the speed limit that the vehicle was traveling.
For example: Suppose a driver was ticketed for driving 42 mph in a 30 mile per hour zone. He was going 12 miles over the limit (42-30 = 12). The ticket would be:
$20 + $5.00 X (42-30) = $80
Use variables for:
Speed limit (Both will be whole numbers entered from the keyboard.)
User speed
Sample Screen Output:
Enter the speed limit: 30
Enter the vehicle speed: 42
The fine will be: $80
Sample Screen Output:
Enter the speed limit: 55
Enter the vehicle speed: 70
The fine will be: $95
Use “method” for your input. Make sure that your screen output looks similar to the sample output above.
Program #2
Program Description: Write a program that inputs the radius of a circle from the user. The program will attractively output the area and circumference of the circle, as well as the volume and surface area of a sphere with the supplied radius.
Use p (PI) =3.14159;
Area = pr2
Circumference = 2pr
Volume = (4/3) pr3
Surface Area = 4pr2
Sample Screen Output:
Enter the radius of a circle: 13.45
A circle with radius 13.45 has:
Area of 568.321484975
Circumference of 84.508771
Volume of 10191.8986305
Surface Area of 2273.2859399
Use “method” for you
Explanation / Answer
Question 1:
FineCalc.java
import java.util.Scanner;
public class FineCalc {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter the speed limit: ");
int limit = scan.nextInt();
System.out.println("Enter vehicle speed: ");
int speed = scan.nextInt();
int baseFine = 20;
int finalFine = baseFine + 5 * (speed- limit);
System.out.println("The fine will be: $"+finalFine);
}
}
Output:
Enter the speed limit:
30
Enter vehicle speed:
42
The fine will be: $80
Question 2:
CircleAreaTest.java
import java.util.Scanner;
public class CircleAreaTest {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
final double p = 3.14159;
System.out.println("Enter the radius of a circle: ");
double r = scan.nextDouble();
double circleArea = p * r * r;
double circumference = 2 * p * r;
double volume = (4 * p * r * r * r)/3;
double surfaceArea = 4 * p * r * r;
System.out.println("A circle with radius "+r+" has: ");
System.out.println();
System.out.println("Area of "+circleArea);
System.out.println("Circumference of "+circumference);
System.out.println("Volume of "+volume);
System.out.println("Surface Area of "+surfaceArea);
}
}
Output:
Enter the radius of a circle:
13.45
A circle with radius 13.45 has:
Area of 568.321484975
Circumference of 84.508771
Volume of 10191.898630551665
Surface Area of 2273.2859399
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.