Pizza Order – If-Else Statements & Switch Statements

import java.util.Scanner;

/*AniBlogger12
 * Pizza Order
 */
public class PO {
// main
	public static void main(String[] args) {
// get keyboard for user input
		Scanner kb = new Scanner(System.in);
// prompt user
		System.out.println("Please enter the size of the pizza (12, 14, or 16 inch)");
// make size variable
		double size = kb.nextDouble();
// prompt user asking for number of toppings
		System.out.println("Please enter the number of toppings");
// user input for number of toppings
		int toppings = kb.nextInt();
// deduct $5.50 away from toppings 
		double newtoppings = toppings - 5.5;
// toppings price variable
		double tprice;
// switch statement
		switch (toppings) {
// first case, no toppings price
		case 0:
			tprice = 0;
			break;
// second case, $2
		case 1:
			tprice = 2;
			break;
// third case, $3
		case 2:
			tprice = 3;
			break;
// if not the above, price is $3 plus $.50 ^ # of toppings
		default:
			tprice = 3 + Math.pow(.50, newtoppings);
		}
// pizza prices for size 12, 14, and 16 pizzas
		double price1 = 9.00;
		double price2 = 11.00;
		double price3 = 14.00;
// if the pizza size is 12, add $9.00 to the toppings price and print out
		if (size == 12) {
			price1 += tprice;
			System.out.println("The cost of the pizza is " + price1);
		}
// if the pizza size is 14, add $11.00 to the toppings price and print out
		if (size == 14) {
			price2 += tprice;
			System.out.println("The cost of the pizza is " + price2);
		}
// if the pizza size is 16, add $14.00 to the toppings price and print out
		if (size == 16) {
			price3 += tprice;
			System.out.printf("The cost of the pizza is " + price3);

		}
	}

}

Program to Find the Average of 5 Grades

import java.util.Scanner;

/* AniBlogger12
 * Finding the letter grade based on the percent grade entered
 */
public class AGRP {

	public static void main(String[] args) {
		System.out.println("Please enter 5 of your grades in integers:");
		Scanner kb = new Scanner(System.in);
// 5 grades inputed 
		int g1 = kb.nextInt();
		int g2 = kb.nextInt();
		int g3 = kb.nextInt();
		int g4 = kb.nextInt();
		int g5 = kb.nextInt();
//average grade
		double grade = (g1 + g2 + g3 + g4 + g5) / 5;
//grade rounded to nearest integer: use Math.rint and cast it to make it an int.
		int rgrade = (int) Math.rint(grade);
// grade rounded and printed out to the nearest 10th, use %.1f.%n to round it one decimal place to the left
		System.out.printf("The grade rounded to the nearest tenth is %.1f.%n", grade);
// If the grade is greater than or equal to(>=) 90, the grade is an A.
		if (Math.rint(rgrade) >= 90) {
			System.out.println("The grade is an A.");
		}
// If it isn't, then if the grade is greater than or equal to(>=) 80
		else if (rgrade >= 80 ) {
			System.out.println("The grade is a B.");
		}
//If it isn't, then if the grade is greater than or equal to(>=) 70
		else if (rgrade >= 70 ) {
			System.out.println("The grade is a C.");
		}
//If it isn't, then if the grade is greater than or equal to(>=) 60
		else if (rgrade >= 60 ) {
			System.out.println("The grade is a D.");
		}
//If it isn't, then if the grade is less than(<) 60, it is an F.
		else if (rgrade < 60) {
			System.out.println("The grade is an F.");
		}
	}

}

Design a site like this with WordPress.com
Get started