Skip to content

Commit 15abd3b

Browse files
committed
hw3
1 parent 76519a0 commit 15abd3b

File tree

8 files changed

+123
-2
lines changed

8 files changed

+123
-2
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package homework.section3;
2+
3+
import java.util.Scanner;
4+
5+
public class CalculateGratuity {
6+
7+
public static void main(String[] args) {
8+
Scanner input = new Scanner(System.in);
9+
System.out.print("Enter the subtotal and a gratuity rate: ");
10+
int subtotal = input.nextInt();
11+
int gratuityRate = input.nextInt();
12+
double gratuity = subtotal * gratuityRate / 100.0;
13+
double total = subtotal + gratuity;
14+
System.out.println("The gratuity is $" + gratuity + " and total is $" + total);
15+
}
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package homework.section3;
2+
3+
import java.util.Scanner;
4+
5+
public class CalculateInterest {
6+
7+
public static void main(String[] args) {
8+
Scanner input = new Scanner(System.in);
9+
System.out.println("Enter balance and interest rate: ");
10+
double balance = input.nextDouble();
11+
double annualInterestRate = input.nextDouble();
12+
13+
double interest = balance * (annualInterestRate / 1200);
14+
15+
System.out.println("The interest is " + interest);
16+
}
17+
}

src/main/java/homework/section3/CelsiusToFahrenheit.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ public class CelsiusToFahrenheit {
66

77
public static void main(String[] args) {
88
Scanner input = new Scanner(System.in);
9-
System.out.println("Enter a degree in Celsius: ");
9+
System.out.print("Enter a degree in Celsius: ");
1010
int celsius = input.nextInt();
11-
11+
double fahrenheit = (9.0 / 5) * celsius + 32;
12+
System.out.println(celsius + " Celsius is " + fahrenheit + " Fahrenheit");
1213
}
1314
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package homework.section3;
2+
3+
import java.util.Scanner;
4+
5+
public class CylinderVolume {
6+
7+
public static void main(String[] args) {
8+
Scanner input = new Scanner(System.in);
9+
System.out.print("Enter the radius and length of a cylinder: ");
10+
double radius = input.nextDouble();
11+
double len = input.nextDouble();
12+
double area = radius * radius * Math.PI;
13+
double volume = area * len;
14+
System.out.printf("The area is %.2f\n", area);
15+
System.out.printf("The volume is %.2f\n", volume);
16+
}
17+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package homework.section3;
2+
3+
import java.util.Scanner;
4+
5+
public class DrivingCost {
6+
7+
public static void main(String[] args) {
8+
Scanner input = new Scanner(System.in);
9+
System.out.println("Enter the driving distance: ");
10+
double distance = input.nextDouble();
11+
System.out.println("Enter miles per gallon: ");
12+
double milesPerGallon = input.nextDouble();
13+
System.out.println("Enter price per gallon: ");
14+
double pricePerGallon = input.nextDouble();
15+
16+
double costOfDriving = (distance / milesPerGallon) * pricePerGallon;
17+
18+
System.out.println("The cost of driving is $" + costOfDriving);
19+
}
20+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package homework.section3;
2+
3+
import java.util.Scanner;
4+
5+
public class FeetToMeter {
6+
7+
public static void main(String[] args) {
8+
Scanner input = new Scanner(System.in);
9+
System.out.print("Enter a value for feet: ");
10+
double feet = input.nextDouble();
11+
double meter = feet * 0.305;
12+
System.out.printf("%.2f feet is %.4f meters", feet, meter);
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package homework.section3;
2+
3+
import java.util.Scanner;
4+
5+
public class PoundToKg {
6+
7+
public static void main(String[] args) {
8+
Scanner input = new Scanner(System.in);
9+
System.out.print("Enter a number in pounds: ");
10+
double pound = input.nextDouble();
11+
double kg = pound * 0.454;
12+
System.out.println(pound + " pounds is " + kg + " kilograms");
13+
}
14+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package homework.section3;
2+
3+
import java.util.Scanner;
4+
5+
public class SumDigits {
6+
7+
public static void main(String[] args) {
8+
Scanner input = new Scanner(System.in);
9+
System.out.print("Enter a number between 0 and 1000: ");
10+
int number = input.nextInt();
11+
while (number > 1000 || number < 0) {
12+
System.out.print("Enter a number between 0 and 1000: ");
13+
number = input.nextInt();
14+
}
15+
int sumDigit = 0;
16+
while (number != 0) {
17+
sumDigit += number % 10;
18+
number /= 10;
19+
}
20+
System.out.println("The sum of the digits is " + sumDigit);
21+
}
22+
}

0 commit comments

Comments
 (0)