In: Computer Science
A phone company charges 0.25 AED per minutes for the first 100 minutes and 0.45 AED for each extra minutes.
The company also rewards customers with points. If the bill is less than or equal to 20.00 AED, 10 points will be rewarded, otherwise, 1 point will be rewarded for each 2 AED.
Write a Java Program to prompt the user to input the number of minutes he/she used, then output the bill amount and number of points rewarded. Note that points should be presented as integer numbers.
Java language
run=
Enter the number of minutes: 124
The bill is: 35.8
The number points awarded is: 17
BUILD SUCCESSFUL (total time: 6 seconds)
run:
Enter the number of minutes: 45
The bill is: 11.25
The number points awarded is: 10
BUILD SUCCESSFUL (total time: 4 seconds)
The code for executing the above problem is given below
// import the Scanner class
import java.util.Scanner;
// A class is created
public class BillGenerator {
//A method is created for generating the reward
points
static void rewardedPoint(double aed){
//condition checking
if(aed <= 20){
//Print the awarded points as 10 if AED is less than
20
System.out.println("The number of point awarded is:" + 10);
}
else{
double awardedPoint = aed / 2;
//Double value is converting to integer
value.
int awardPoint = (int) awardedPoint;
//Printing the total rewarded points if AED is greater
than 20.
System.out.println("The number of point awarded is:" +
awardPoint);
}
}
//Main method is created
public static void main(String[] args) {
//scanner for reading value from the user
Scanner myObj = new Scanner(System.in);
//Two variables were declared
int minute;
double aed = 0;
System.out.print("Enter the number of minutes:");
minute = myObj.nextInt();
//If the condition satisfy then the aed value will be
calculated.
if(minute <= 100){
aed = minute * 0.25;
}
//Condition not satisfy then the below statements will
execute
else{
double extraMinute = (minute - 100);
aed = (100 * 0.25) + (extraMinute * 0.45);
}
//The total AED will print
System.out.println("The bill is: "+ aed);
//calling the rewarded point method to calculate the
rewarded point by passing the AED value.
rewardedPoint(aed);
}
}
OUTPUT 1:
Enter the number of minutes: 124
The bill is: 35.8
The number points awarded is: 17
OUTPUT 2:
Enter the number of minutes: 45
The bill is: 11.25
The number points awarded is: 10
The screenshot of the code and the output are given below.
OUTPUT 1:
OUTPUT2: