⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex1partd.java

📁 Snunuiot are flying as far as you send them... and then they die ha ha ha
💻 JAVA
字号:
import java.util.Scanner;

public class Ex1PartD {

	public static void main(String[] args) {
		
		//		variable declaration:
		int distance, coconutLocation, coconutWeight,iTmpWght, iTmpEff, iTmpCon, iTmpBeu;;
		int africanWeight, africanEfficiency, africanConcentration, africanBeauty;
		int europeanWeight=0, europeanEfficiency=0, europeanConcentration=0, europeanBeauty=0;
		double dEurWinProb,dEurTime,dAfrTime,dBstWinPrb=0;
		double afTime, euTime, euWinProb, euCocoDropProb, afCocoDropProb;

		//		input		
		Scanner sc = new Scanner(System.in);

		System.out.print("Enter flight distance (between 500m and 1000m): ");
		distance = sc.nextInt();
		while (distance < 500 | distance > 1000){
			System.out.println("Invalid input!");
			System.out.print("Enter flight distance (between 500m and 1000m): ");
			distance = sc.nextInt();
		}
		
		
		System.out.print("Enter distance between starting point and coconut tree(between 0m and "+
			distance +"m): ");
		coconutLocation = sc.nextInt();
		while (coconutLocation < 0 | coconutLocation > distance){
			System.out.println("Invalid input!");
			System.out.print ("Enter distance between starting point and coconut tree"+
			 "(between 0m and "+distance+"m): ");
			coconutLocation = sc.nextInt();
		}
		
		System.out.print("Enter coconut shell weight (between 100g and 200g): ");
		coconutWeight = sc.nextInt();
		while (100 > coconutWeight | coconutWeight > 200){
			System.out.println("Invalid input!");
			System.out.print("Enter coconut shell weight (between 100g and 200g): ");
			coconutWeight = sc.nextInt();
		}
		
		System.out.println();
		
		System.out.print("Enter African swallow weight (between 20g and 30g): ");
		africanWeight = sc.nextInt();
		while (africanWeight < 20 | africanWeight > 30){
			System.out.println("Invalid input!");
			System.out.print("Enter African swallow weight (between 20g and 30g): ");
			africanWeight = sc.nextInt();
		}
		
		System.out.print("Enter African swallow efficiency, concentration, and beauty.\n"+
			"Each argument must be between 0 and 100, and the sum of all arguments"+
				" must be equal to 100.\n");
		
		System.out.print("Efficiency: ");
		africanEfficiency = sc.nextInt();
		System.out.print("Concentration: ");
		africanConcentration = sc.nextInt();
		System.out.print("Beauty: ");
		africanBeauty = sc.nextInt();

		while ((africanBeauty+africanConcentration+africanEfficiency!=100) | (africanEfficiency < 0 | africanEfficiency > 100) | 
				(africanConcentration < 0 | africanConcentration > 100) | (africanBeauty < 0 | africanBeauty > 100)){	
			System.out.print("Invalid input!\nEnter African swallow efficiency, concentration,"+
				" and beauty.\nEach argument must be between 0 and 100, and the sum of all"+
					"arguments must be equal to 100.\n");
			System.out.print("Efficiency: ");
			africanEfficiency = sc.nextInt();
			System.out.print("Concentration: ");
			africanConcentration = sc.nextInt();
			System.out.print("Beauty: ");
			africanBeauty = sc.nextInt();
		}


//		counting best parameters for European bird:
		
		for (iTmpWght=15;iTmpWght<25;iTmpWght++){
			for (iTmpBeu=0;iTmpBeu<100;iTmpBeu++){
				for (iTmpCon=0;iTmpCon<100;iTmpCon++){
					iTmpEff=100-iTmpCon-iTmpBeu;
					
					euCocoDropProb = 0.5 - (double) iTmpCon / 200;
					afCocoDropProb = 0.5 - (double) africanConcentration / 200;
			
					if (iTmpBeu > africanBeauty) euWinProb = afCocoDropProb;
					else euWinProb = afCocoDropProb * (1 - euCocoDropProb);
		
					afTime = coconutLocation * (africanWeight + (double) coconutWeight/8) / (10 * (africanWeight + 10))+
								 coconutLocation * (africanWeight + (double) coconutWeight/8) / 
								 	(10 * (africanWeight + 10))- africanEfficiency; 
					euTime = coconutLocation * (iTmpWght + (double) coconutWeight/8) / (10 * (iTmpWght + 10))+
								 coconutLocation * (iTmpWght + (double) coconutWeight/8) / 
								 	(10 * (iTmpWght + 10))- iTmpEff; 

					if (euTime < afTime) euWinProb += (1 - euCocoDropProb) * (1 - afCocoDropProb);
		
					if (euWinProb>dBstWinPrb){
						dBstWinPrb=euWinProb;
						europeanWeight = iTmpWght;
						europeanBeauty = iTmpBeu;
						europeanEfficiency = iTmpEff;
						europeanConcentration = iTmpCon;
					}
				}
			}
		}
		
		/********************************************************************
		 * 	The following code MUST NOT BE CHANGED!!! 
		 *  This code prints the European swallow characteristics,
		 *  and compute its winning probability.
		 *  
		 *  Important! In order for the following code to compile, you must
		 *  put the file ProbabilityCalculator.java in the same directory
		 *  as this file. You may not change the code in 
		 *  ProbabilityCalculator.java.
		 ********************************************************************/
	
		System.out.println();
		System.out.println("European swallow:");
		System.out.println("Weight: " + europeanWeight + "g, efficiency: " + europeanEfficiency + ", concentration: "
				+ europeanConcentration +", beauty: " + europeanBeauty + ".");

		ProbabilityCalculator.europeanWinProb(distance, coconutLocation, coconutWeight, africanWeight, africanEfficiency, 
				africanConcentration, africanBeauty, europeanWeight, europeanEfficiency, europeanConcentration, europeanBeauty);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -