Notice
Recent Posts
Recent Comments
Link
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
Tags more
Archives
Today
Total
관리 메뉴

공부블로그

1일 1코딩 본문

IT/알고리즘

1일 1코딩

So1_b 2022. 4. 9. 23:14
package basic.data_tructure;
import java.util.Scanner;

import basic.data_tructure.PhysicalExamination.PhyscData;

public class Q10 {
	static final int VMAX=21;
	
	static class PhyscData{
		String name;//이름
		int height; //키
		double vision; //시력
		
		PhyscData(String name, int height, double vision){
			this.name=name;
			this.height=height;
			this.vision=vision;
		}
	}
	//평균 키
	static double aveHeight(PhyscData[] dat) {
		double sum=0;
		for(int i=0; i<dat.length; i++) sum+=dat[i].height;
		return sum/dat.length;
	}
	
	//시력분포
	static void distVision(PhyscData[] dat, //초기화 되어 있음
								int[] dist) { //초기화 안되어 있음.
		int i=0;
		dist[i]=0;
		
		for(i=0;i<dat.length;i++) {
			if(dat[i].vision>=0.0&&dat[i].vision<=2.0)
				dist[(int)(dat[i].vision*10)]++;
		}
	}
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int num=0;
		
		PhyscData[] x= {
				new PhyscData("박현규", 162, 0.3),
				new PhyscData("함진아", 173, 2.0),
				new PhyscData("최윤미", 175, 2.0),
				new PhyscData("홍연의", 171, 1.5),
				new PhyscData("이수진", 168, 0.4),
				new PhyscData("김영준", 174, 1.2),
				new PhyscData("박용규", 169, 0.8),
		};	
		int[] vdist=new int[VMAX];
		
		System.out.println("신체검사 리스트");
		System.out.printf("%-8s%-4s%-3s\n","이름","키","시력");
		System.out.println("----------------------------");
		
		for(int i=0;i<x.length;i++) {
			System.out.printf("%-8s%3d%5.1f\n",
							x[i].name,x[i].height,x[i].vision);
		}System.out.printf("\n평균 키: %5.1fcm\n",aveHeight(x));
		
		distVision(x, vdist);
		
		for(int i=0;i<vdist.length;i++) {
			System.out.printf("%3.1f ~ :",i/10.0);
			
			num=vdist[i]; //인원수
			while(num>0) {
				System.out.print("*");
				num--;
			}System.out.println();
		}
	}
	
}

'IT > 알고리즘' 카테고리의 다른 글

1일 1코딩  (0) 2022.04.10
1일 1코딩  (0) 2022.04.10
1일 1코딩  (0) 2022.04.08
1일1코딩  (0) 2020.09.10
1일1코딩_상속문제  (0) 2020.09.09
Comments