Spaces:
Running
Running
Create 9. Calculate the total salary
Browse files
Week 1: Types, condition clauses and loops/9. Calculate the total salary
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
Write a program that asks the user to enter the number of working days (integer) and the daily wage (float).
|
| 3 |
+
|
| 4 |
+
The program calculates the user's total salary based on this information.
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
If there are more than 5 working days, the total salary will be increased by 20%.
|
| 9 |
+
|
| 10 |
+
However, if there are more than 10 working days, the increase in the total salary is 50%.
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
Example output:
|
| 15 |
+
Workdays: 11
|
| 16 |
+
Daily salary: 8.50
|
| 17 |
+
Total salary: 140.25
|
| 18 |
+
'''
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
import java.util.Random;
|
| 23 |
+
import java.util.Scanner;
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
public class Test{
|
| 28 |
+
public static void main(String[] args){
|
| 29 |
+
final Random r = new Random();
|
| 30 |
+
|
| 31 |
+
Scanner reader = new Scanner(System.in);
|
| 32 |
+
System.out.print("Workdays: ");
|
| 33 |
+
int days = Integer.valueOf(reader.nextLine());
|
| 34 |
+
|
| 35 |
+
System.out.print("Daily salary: ");
|
| 36 |
+
double dailysal = Double.valueOf(reader.nextLine());
|
| 37 |
+
|
| 38 |
+
double totalsal = days * dailysal;
|
| 39 |
+
if (days>10) {
|
| 40 |
+
totalsal*=1.5;
|
| 41 |
+
}
|
| 42 |
+
else if (days>5) {
|
| 43 |
+
totalsal*=1.2;
|
| 44 |
+
}
|
| 45 |
+
else {
|
| 46 |
+
totalsal=totalsal;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
System.out.println("Total salary: "+totalsal);
|
| 51 |
+
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
'''
|
| 58 |
+
Testing with inputs 2, 10.0
|
| 59 |
+
Workdays: 2
|
| 60 |
+
Daily salary: 10.0
|
| 61 |
+
Total salary: 20.0
|
| 62 |
+
|
| 63 |
+
Testing with inputs 9, 5
|
| 64 |
+
Workdays: 9
|
| 65 |
+
Daily salary: 5
|
| 66 |
+
Total salary: 54.0
|
| 67 |
+
|
| 68 |
+
Testing with inputs 11, 8.50
|
| 69 |
+
Workdays: 11
|
| 70 |
+
Daily salary: 8.50
|
| 71 |
+
Total salary: 140.25
|
| 72 |
+
|
| 73 |
+
Testing with inputs 17, 10.0
|
| 74 |
+
Workdays: 17
|
| 75 |
+
Daily salary: 10.0
|
| 76 |
+
Total salary: 255.0
|
| 77 |
+
'''
|