【牛客网】学习绩点

学分绩点

题目链接
【题目描述】
北京大学对本科生的成绩施行平均学分绩点制(GPA)。即将学生的实际考分根据不同的学科的不同学分按一定的公式进行计算。公式如下:实际成绩 绩点 90——100 4.0,85——89 3.7,82——84 3.3,78——81 3.0,75——77 2.7,72——74 2.3 ,68——71 2.0,64——67 1.5,60——63 1.0,60以下0。
1.一门课程的学分绩点=该课绩点*该课学分
2.总评绩点=所有学科绩点之和 / 所有课程学分之和
现要求你编写程序求出某人A的总评绩点(GPA)
【输入描述】
第一行:总的课程数n(n<10);
第二行:相应的课程的学分(两个学分间用空格隔开);
第三行:对应课程的实际得分;
此处输入的所有数字均为整数
【输出描述】
输出有一行,总评绩点,精确到小数点后2位小数。(printf(“%。2f”,GPA);)
【示例】
输入
5
4 3 4 2 3
91 88 72 69 56
输出
2.52

【代码实现】

/**
 *
 * @Title:
 * @Author: aaa
 * @DATE: 2020/3/4
 *
 **/
import java.util.Scanner;
public class ScorePoint
{
	//获得对应分数的对应绩点
    public static double getPoint(int grade)
    {
        if(grade>=90&&grade<=100)
        {
            return 4.0;
        }
        else  if(grade>=85&&grade<=89)
        {
            return 3.7;
        }else  if(grade>=82&&grade<=84)
        {
            return 3.3;
        }
        else  if(grade>=78&&grade<=81)
        {
            return 3.0;
        }
        else  if(grade>=75&&grade<=77)
        {
            return 2.7;
        }
        else  if(grade>=72&&grade<=74)
        {
            return 2.3;
        }
        else  if(grade>=68&&grade<=71)
        {
            return 2.0;
        }
        else  if(grade>=64&&grade<=67)
        {
            return 1.5;
        }
        else  if(grade>=60&&grade<=63)
        {
            return 1.0;
        }
        else
        {
            return 0.0;
        }
    }
    public static void main(String[]args)
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();				//课程数目
        int []score=new int[n];			//课程学分
        int []grade=new int[n];			//实际得分
        double allscore=0;
        double allpoint=0;
        for(int i=0;i<n;i++)
        {
            score[i]=sc.nextInt();
            allscore+=score[i];
        }
        for(int i=0;i<n;i++)
        {
            grade[i]=sc.nextInt();
            allpoint+= getPoint(grade[i])*score[i];
        }
        double GPA=allpoint/allscore;
        System.out.printf("%.2f",GPA);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值