اتفضل ..
كود PHP:
import java.util.Scanner;
public class Assign1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
// To calculate the electricity and water charges you need the following information
String E_Consumer_name ;
int E_consumer_id,
E_previous_reading = 0,
E_current_reading = 0,
E_previous_unpaid_amount = 0,
W_current_amount = 0 ,
W_previous_unpaid_amount = 0;
//consumer charged 0.05 SAR per unit
final double consumer_charge_Amount = 0.05;
//monthly service charges for electricity is 10 SAR
final double E_monthly_charge = 10;
//charged for monthly water service is 7 SAR
final double W_monthly_charge = 7;
System.out.println(" Welcome to Electricity and Water Services Center");
System.out.println(" ================================================");
Scanner sc = new Scanner(System.in);
System.out.print("Please Enter Your Name: ");
E_Consumer_name = sc.next();
System.out.print("Please Enter Your ID: ");
E_consumer_id = sc.nextInt();
System.out.println("\n"+"Please Enter The Following Information for Electricity Service:");
System.out.print("Current Miter Reading: ");
E_current_reading = sc.nextInt();
System.out.print("Previous Miter Reading: ");
E_previous_reading = sc.nextInt();
System.out.print("Previous unpaid amount: ");
E_previous_unpaid_amount = sc.nextInt();
System.out.print("\nPlease Enter The Following Information for Water Service:"+"\n"+"Current Amount: ");
W_current_amount = sc.nextInt();
System.out.print("Previous unpaid amount: ");
W_previous_unpaid_amount = sc.nextInt();
//formula to calculate the electricity bill
double E_curr= (E_current_reading - E_previous_reading) * consumer_charge_Amount + E_monthly_charge;
double E_total = E_curr + E_previous_unpaid_amount;
//formula to calculate the water bill
double W_Amount = W_current_amount + W_monthly_charge + W_previous_unpaid_amount;
System.out.println(" The Electricity and Water Bill");
System.out.println(" ==============================");
System.out.println("Name:"+E_Consumer_name+" "+"ID:"+E_consumer_id+"\n"+
"Monthly Electricity service Charge: "+E_monthly_charge+" SAR"+" "+
" Charge Per Unit: "+consumer_charge_Amount+" SAR"+"\n"+
" Monthly water service Charge: "+W_monthly_charge+" SAR");
System.out.println("------------------------------------------------------------------------------------------------------------------------"+
"\n"+"S.No Service Previous Reading Current Reading Current Amount Unpaid Amount Total");
System.out.println("1 Electricity "+E_previous_reading+
" "+E_current_reading+
" "+E_curr+
" "+E_previous_unpaid_amount+
" "+E_total);
System.out.println("2 Water 0"+
" 0"+" "+
(W_current_amount+W_monthly_charge)+" "+
W_previous_unpaid_amount+" "+W_Amount+
"\n------------------------------------------------------------------------------------------------------------------------");
double total_E_W = E_total+W_Amount;
System.out.println(" Grand Total : "+(total_E_W));
System.out.println(" Percentage of the Electricity : "+((E_total/total_E_W)*100)+"%");
System.out.println(" Percentage of the Water : "+((W_Amount/total_E_W)*100)+"%");
}
}
ودا الأوتبوت
بالتوفيق ..