7-1 sdut-JAVA- The total cost
分数 17
全屏浏览
作者 马新娟
单位 山东理工大学
CSIS Radio offers each winner of a competition the choice of 2 books from one of three categories. The management has requested you to write a Java program that will allow them to enter the category chosen by a winner and your program will calculate the total cost of sending the books to this winner. The total cost comprises the cost of the books chosen as well as an additional cost of €10 for postage and packaging. If a book category other than those shown in the following table is entered, your program should display an “Invalid book category: 1, 2 and 3 are valid categories.” message.
Input Specification:
Enter category selected by winner.
Output Specification:
the total cost of sending the books to this winner. If a book category other than those shown in the following table is entered, your program should display an “Invalid book category: 1, 2 and 3 are valid categories.” message.
Sample Input:
1
Sample Output:
Cost of prize = 75.0
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
栈限制
8192 KB
import java.util.Scanner; public class Main { public static void main(String [] args) { Scanner in =new Scanner(System.in); int n; n=in.nextInt(); if(n==1||n==2||n==3) { if(n==1) { System.out.println("Cost of prize = "+75.0); } else if(n==2) { System.out.println("Cost of prize = "+(30*2+10)); } else if(n==3) { System.out.println("Cost of prize = "+(25.75*2+10)); } } else{ System.out.println("Invalid book category: 1, 2 and 3 are valid categories."); } } }