java Computing Cost Class Topics

Telecom Billing

A telecom company's mobile phone call fee calculation program
A company designed a mobile phone fee package, see the table below.
Set type: domestic basic call length, excess of part charge, free short message package, excess of part charge, domestic data flow, excess of part charge, set price
A set meal 250min 0.25/min 100 pieces 0.1 yuan/piece 50MB 0.3 yuan/MB 58 yuan/month
* The basic call time less than 1 minute is calculated in 1 minute; the data flow less than 1M is calculated in 1M.
Require to write a program to read in the user's domestic calls from the console this month, the number of short messages and data traffic, calculate the user's stressful calls this month (excluding international and Hong Kong, Macao and Taiwan calls and other value-added services).

import java.util.Scanner;
public class Test1109{
	public static void main(String[] args){
		
		/*Define call double
		Short message number msg int
		flow double
		Fee double fee
		
		call_fee double for excess calls
		msg_fee double
		flow_fee double*/
		Scanner sca = new Scanner(System.in);
		System.out.println("Please enter the length of the call:");
		double call = sca.nextDouble();
		System.out.println("Please enter the number of short messages:");
		int msg = sca.nextInt();
		System.out.println("Please enter the number of traffic used:");
		double flow = sca.nextDouble();
		double fee= 58 ;
		//The Math.ceil() method performs an upward integer calculation, which returns an integer that is greater than or equal to the function parameter and closest to it.
		if (call>250){
			fee+=Math.ceil(call-250)*0.25;
		}
		if (msg>100){
			fee+=Math.ceil(msg-100)*0.1;
		}
		if (flow>50){
			fee+=Math.ceil(flow-50)*0.3;
		}
		
		System.out.println("Total tariff:"+fee);
		
		
	}
}

Parking cost

The parking fee rules are as follows: no charge in 15 minutes, more than 15 minutes to 2 hours, 2 yuan, 2 hours, 3 yuan per hour.
Less than one hour is calculated according to one hour. The parking lot has a maximum charge of 50 yuan, and the number of minutes from the keyboard is stopped.
If the number of minutes is less than 0, the error will be prompted. If the input is correct, the parking fee will be calculated and output.

import java.util.Scanner;
public class Test4{
	public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		System.out.println("Please enter parking minutes.");
		double b=0;     //Type double
		double a =sc.nextDouble();
		if (a<=0){
			System.out.println("Minute error!");
		}else if (a<=15){
			b=0;
		}else if(a<(60*2)){
			b=2;
		}else {
			b=Math.ceil((a-(60*2))/60)*3+2;  
			//The Math.ceil() method performs an upward integer calculation, which returns an integer that is greater than or equal to the function parameter and closest to it.
		}
		if (b>50){
			b=50;    //The maximum charge for parking lots is 50 yuan.
		}
		System.out.println("You stopped."+a+"Minute"+"Fees payable"+b+"element");
	}
}

Letter cost

import java.util.Scanner;
public class Test1108{
	public static void main(String[] args){
		Scanner sc= new Scanner(System.in);
		double a=0;
		double fee=0;
		int n=0;
		int w=0;
		double z=0;
		System.out.println("Please enter the weight of the letter.");
		while(true){
			a=sc.nextInt();
			if(a<=0){
				System.out.println("Wrongful");
				break;
			}else if(a>2000){
                System.out.println("Overweight, please re-enter");
				continue;
			}
			//The Math.ceil() method performs an upward integer calculation, which returns an integer that is greater than or equal to the function parameter and closest to it.
			if(a<=100){
				fee=Math.ceil(a/20)*1.2;
				n++;
			}else{
			fee=Math.ceil((a-100)/100)*3.6+6; //Calculating parking fees
			    w++;
			}
			z=z+fee;
			System.out.println("The cost of correspondence is"+fee);
		}
		System.out.println("Number of letters weighing less than 100"+n+"Number of letters weighing more than 100"+w);
		System.out.println("The total tariff is"+z);
	}
}

Keywords: less Java Mobile

Added by bandit8 on Mon, 30 Sep 2019 11:59:51 +0300