IN CONDITIONAL STATEMENT JAVA,
Outcomes:
Create a program solution of the given problem applying Java conditional
statements
Differentiate If, if-else and if-else if-else statements
Use comparison and logical operators to handle conditional statements in java program.
Instruction:
Read and analyze each problem. Provide a JAVA program to satisfy the required
machine functionality.
Import all java utilities using the syntax: Import java.util.*;
Machine Problem:
Create a java program that would compute and display the total mobile services fee
incurred by a customer. Mobile services include text messages, calls in minutes and
mobile data usage in megabytes.
Each customer was given a customer ID that would indicate the type of mobile plan
he/she availed.
PLAN A
- Customer ID ending
with 0. Loyal member
has 5 digits and above
ID number.
- monthly fixed rate of
P500.00
- allows free text
messaging up to 250
messages. Beyond
that, each message is
charged 90 centavos.
- All-net calls up to 60
mins. Exceeding
minutes applies
P5/min.
- P5/MB. Free use of
mobile data up to
80MB.
- 20% discount from
the total charge for
Loyal member.
PLAN B
- Customer ID ending
with 5. Loyal member
has 5 digits and above
ID number.
- monthly fixed rate of
P750.00
- allows free text
messaging of up to 500
messages. Beyond
that, each message is
charged 70 centavos.
- All-net calls up to 120
mins. Exceeding
minutes applies
P5/min.
- P5/MB. Free use of
mobile data up to
100MB.
- 40% discount from the
total charge.
PLAN C
- Customer ID ending
with 2. Loyal member
has 5 digits and above
ID number.
- monthly fixed rate of
P1,200.00
- allows free text
messaging of up to
1,000 messages.
Beyond that, each
message is charged 50
centavos.
- All-net calls up to 240
mins. Exceeding
minutes applies P5/mins
- P5/MB. Free use of
mobile data up to
500MB.
- 60% discount from the
total charge.
INPUT: The first line of the input file will contain a single integer N that represents the
Customer ID number. Next line consists of 3 integer T, C and D, separated by commas
(,). T is the total number of text messages; C is the total number of calls in minutes and D
is the total data usage in MB.
OUTPUT: The total mobile fee of the customer applying all charges given in the
description and discounts if applicable. In addition, the program must also display an
offer to upgrade the plan type for customers who have exceeded their monthly fixed
rate by 200%. Ex. Plan A – total bill of P1,860.00 means the customer exceeded by
P1,360.00 or 272% from his/her monthly fixed rate of P500 (P1,860-500=1,360).
TEST CASE:
CUSTOMER ID: 39480
300 128 100
----------------------------------------------------
TOTAL ID: P 788.00
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String id = in.nextLine();
String[] tcd = in.nextLine().split(",");
int messages = Integer.parseInt(tcd[0]);
int calls = Integer.parseInt(tcd[1]);
int data = Integer.parseInt(tcd[2]);
double fixedRate = 0;
double total = 0;
if (id.charAt(id.length() - 1) == '0') {
fixedRate = 500;
total += fixedRate;
if (messages > 250) {
total += 0.9 * (messages - 250);
}
if (calls > 60) {
total += 5 * (calls - 60);
}
if (data > 80) {
total += 5 * (data - 80);
}
if (id.length() >= 5) {
total *= 0.8;
}
} else if (id.charAt(id.length() - 1) == '5') {
fixedRate = 750;
total += fixedRate;
if (messages > 500) {
total += 0.7 * (messages - 500);
}
if (calls > 120) {
total += 5 * (calls - 120);
}
if (data > 100) {
total += 5 * (data - 100);
}
total *= 0.6;
} else if (id.charAt(id.length() - 1) == '2') {
fixedRate = 1200;
total += fixedRate;
if (messages > 1000) {
total += 0.5 * (messages - 1000);
}
if (calls > 240) {
total += 5 * (calls - 240);
}
if (data > 500) {
total += 5 * (data - 500);
}
total *= 0.4;
}
if ((total - fixedRate) / fixedRate > 2) {
System.out.println("You need to upgrade your plan type.");
}
System.out.println("TOTAL " + id + ": P " + total);
}
}
Comments
Leave a comment