Introduction 1
- Question
- Answer
As part of promotion, a department store provides discounts for its customers.
All products whose prices are above IDR 300,000 are given a discount of 40%. For example, a pair of shoes that cost IDR 499,000 are now sold for only IDR 299,400.
However, the labels printed on the products are still showing prices before the discount, so the department store employee still needs to calculate in advance to get the final price.
Write a program to help department store employees to calculate the final price of the products.
Introduction 2
- Question
- Answer
Because the strategy of providing discounts successfully attracted customers, department store management plans to hold additional events. On the 7th of each month, department stores will provide an additional discount of 20% for all products. For products with prices above IDR 300,000, of course the discounts obtained will double.
For example, for a bag worth IDR 1,000,000, the initial discount obtained is 40% x IDR 1,000,000 = IDR 400,000 so the price of the item before the additional discount = IDR 600,000.
With an additional discount of 20%, the total to be paid is IDR 600,000 - (20% x IDR 600,000) = IDR 480,000.
Update the program you have previously written.
Flag Variables
- Sample Case
- Sample Solution
- Using Flag Variables
Write a program to determine whether the size of the baby at birth is normal
or not
- Normal baby weight at birth ranges from 2.5 to 4.5 kg and lengths between 45 and 60 cm
- Input: baby’s weight in kg and length in cm
- Output: whether the baby’s weight and length are normal, its weight is normal, its length is normal, or both are not normal
Nested Ifs
- Sample Case
- Negative price allowed?
- Solution
Write a program to calculate the total user must pay for an imported item.
- If the price of the item exceeds USD 100, then an import tax of 20% is imposed
- Input: price of items before tax in USD
- Output: total paid (item price plus tax)
Input Validation
- Sample Case
- Solution
- Negative edge length allowed?
- User don't enter a number?
- Return Keyword
Write a program to calculate the volume of the cube
- Input: the length of any edge of the cube
- Output: volume of the cube
String
Strings in Conditionals
String Comparison
- equals
- contains
- startswith/endswith
- compareTo/compareToIgnoreCase
.equals() : digunakan untuk membandingkan isi dari dua buah string, dan mengembalikan true jika isi kedua string tersebut sama.String Manipulation
- substring
- replaceAll/replaceFirst
- toUpperCase/toLowerCase
- trim
.substring() : digunakan untuk mengambil sebagian karakter dari suatu string.String → Number
.parseInt() : digunakan untuk mengubah string menjadi integer..parseDouble() : digunakan untuk mengubah string menjadi double.