美女选妃的基本实现
package com.zhongruan;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Test5 {
public static void main(String[] args){
List hight=new ArrayList<>();
List weight=new ArrayList<>();
hight.add(180);
hight.add(150);
hight.add(160);
hight.add(140);
hight.add(130);
hight.add(160);
hight.add(160);
hight.add(140);
hight.add(169);
hight.add(144);
weight.add(40);
weight.add(50);
weight.add(65);
weight.add(40);
weight.add(38);
weight.add(64);
weight.add(43);
weight.add(53);
weight.add(65);
weight.add(58);
System.out.println(hight);
System.out.println(weight);
int sumH=0;
for(int h:hight){
sumH=sumH+h;
}
System.out.println(sumH);
int sumW=0;
for(int w:weight){
sumW=sumW+w;
}
System.out.println(sumW);
int avgH=sumH/hight.size();
int avgW=sumW/weight.size();
System.out.println(avgH);
System.out.println(avgW);
if(avgH>150 && avgW<100){
System.out.println("是美女");
}
else{
System.out.println("不是美女");
}
}
}
美女选妃方法调用
package com.zhongruan;
import javax.swing.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Test5 {
public List getHights(){
List hight=new ArrayList<>();
hight.add(180);
hight.add(150);
hight.add(160);
hight.add(140);
hight.add(130);
hight.add(160);
hight.add(160);
hight.add(140);
hight.add(169);
hight.add(144);
return hight;
}
public List getWeight(){
List weight=new ArrayList<>();
weight.add(40);
weight.add(50);
weight.add(65);
weight.add(40);
weight.add(38);
weight.add(64);
weight.add(43);
weight.add(53);
weight.add(65);
weight.add(58);
return weight;
}
public Map<String,Integer> getsumHAndSum(List hight,Listweight){
int sumH=0;
for(int h:hight){
sumH=sumH+h;
}
//System.out.println(sumH);
int sumW=0;
for(int w:weight){
sumW=sumW+w;
}
//System.out.println(sumW);
Map map=new HashMap();
map.put("sgh",sumH);
map.put("tzh",sumW);
return map;
}
public Map<String,Integer> getAvg(Map<String,Integer> map){
int sumH=map.get("sgh");
int sumW=map.get("tzh");
int avgH=sumH/3;
int avgW=sumW/3;
Map<String,Integer> avgMap=new HashMap<>();
avgMap.put("pjsg",avgH);
avgMap.put("pjtz",avgW);
return avgMap;
}
public String getResult(Map<String,Integer> avgM){
int avgH=avgM.get("pjsg");
int avgW=avgM.get("pjtz");
if(avgH>150 && avgW<100){
return "是美女";
}
else{
return "不是美女";
}
}
public static void main(String[] args){
Test5 test5=new Test5();
List<Integer> hight=test5.getHights();
List<Integer> weight=test5.getWeight();
test5.getsumHAndSum(hight,weight);
Map<String,Integer> map=test5.getsumHAndSum(hight,weight);
Map<String,Integer> avgM=test5.getAvg(map);
String s=test5.getResult(avgM);
System.out.println(s);
}
}
美女选妃键盘输入
package com.zhongruan;
import javax.swing.;
import java.util.;
public class Test5 {
public Map<String,List> getHights(){
List hight=new ArrayList<>();
List weight=new ArrayList<>();
Scanner input=new Scanner(System.in);
for(int i=1;i<4;i++){
System.out.println(“请输入第”+i+“个美女的身高”);
int h=input.nextInt();
System.out.println(“请输入第”+i+“个美女的体重”);
int w=input.nextInt();
hight.add(h);
weight.add(w);
}
Map<String,List> map=new HashMap<>();
map.put(“sg”,hight);
map.put(“tz”,weight);
return map;
}
public Map<String,Integer> getsumHAndSum(List hight,Listweight){
int sumH=0;
for(int h:hight){
sumH=sumH+h;
}
//System.out.println(sumH);
int sumW=0;
for(int w:weight){
sumW=sumW+w;
}
//System.out.println(sumW);
Map map=new HashMap();
map.put("sgh",sumH);
map.put("tzh",sumW);
return map;
}
public Map<String,Integer> getAvg(Map<String,Integer> map){
int sumH=map.get("sgh");
int sumW=map.get("tzh");
int avgH=sumH/3;
int avgW=sumW/3;
Map<String,Integer> avgMap=new HashMap<>();
avgMap.put("pjsg",avgH);
avgMap.put("pjtz",avgW);
return avgMap;
}
public String getResult(Map<String,Integer> avgM){
int avgH=avgM.get("pjsg");
int avgW=avgM.get("pjtz");
if(avgH>150 && avgW<100){
return "是美女";
}
else{
return "不是美女";
}
}
public static void main(String[] args){
Test5 test5=new Test5();
Map<String,List<Integer>> sgtz= test5.getHights();
List<Integer> hight=sgtz.get("sg");
List<Integer> weight=sgtz.get("tz");
Map<String,Integer> map=test5.getsumHAndSum(hight,weight);
Map<String,Integer> avgM=test5.getAvg(map);
String s=test5.getResult(avgM);
System.out.println(s);
}
}