将双倍增加到下一个整数

时间:2017-01-27 19:37:40

标签: java

我正在研究我的第一个K-State项目及其基础课程,但我的编程有点生疏,而且还没有使用Java。在第二部分中,我们计算了为一个lan派对订购了多少个比萨饼,并假设有一些常数,例如每个披萨多少片(20)以及每个人将吃多少片(2),而现在我正试图拥有它围绕一个双倍计算所需的比萨饼数量。我无法让它正常工作,我知道我做错了什么我不知道是什么。因此,如果有18人参加,18 * 2 = 36.我们需要2个比萨,因为每个人有20个切片。所以我想要做的数学是(18 * 2)/ 20所以你会得到1.8,我希望这个数字被舍入到2,这样我就可以存储它并用它来显示和计算多少个切片遗留下来。

/*
    Proj1.java
    Tristan Stevens / Thursday 6:00pm / Khan

    Calculates user's overall grade percentage and how many pizzas to order/slices leftover
*/

import java.util.*;
import java.lang.*;

public class Proj1
{  
    public static void main(String[] args)
    {
        Scanner s = new Scanner(System.in);

        String input = "";
        final double Total = 290;
        double Grade = 0.0;
        double Points = 0.0;


        System.out.print("Enter in Project score #1 (0-30): ");
        input = s.nextLine();
        Points = Points + Double.parseDouble(input);

        System.out.print("Enter in Project score #2 (0-30): ");
        input = s.nextLine();
        Points = Points + Double.parseDouble(input);

        System.out.print("Enter in Project score #3 (0-30): ");
        input = s.nextLine();
        Points = Points + Double.parseDouble(input);

        System.out.print("\n");

        System.out.print("Enter the midterm exam score (0-100): ");
        input = s.nextLine();
        Points = Points + Double.parseDouble(input);

        System.out.print("Enter the final exam score: (0-100): ");
        input = s.nextLine();
        Points = Points + Double.parseDouble(input);

        Grade = (Points / Total) * 100;

        String output = String.format("Overall grade percentage: %.2f", Grade);
        System.out.println(output + "%");

        System.out.print("\n");

        int People = 0;
        final int slicesPeople = 2;
        final int slicesPizza = 20;

        System.out.print("What is the number of people expected at the pizza party? ");
        input = s.nextLine();
        People = Integer.parseInt(input);

        System.out.print("\n");

        double Pizzas = 0.0;
        Pizzas = Math.ceil((slicesPeople * slicesPizza) / slicesPizza);

        int slicesLeft = 0;

        System.out.format("For %d people, that would be %d pizza(s) with each having %d slices each." , People, Pizzas, slicesPeople);
        System.out.print("\n");
        System.out.format("There would be %d slice(s) leftover.", ((slicesPizza * Pizzas) - (People * slicesPeople)));

        System.out.print("\n");
        System.out.print("\n");
        System.out.print("\n");

    }
}

0 个答案:

没有答案