SDUT JAVA lab3.1

文章描述了一个Java编程任务,要求设计一个程序来计算根据赢家选择的书籍类别(1,2,或3)发送奖品时的总成本,包括书籍费用和固定的10欧元邮寄费。如果输入的类别无效,程序应显示错误消息。
摘要由CSDN通过智能技术生成

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.

 

2874148116c92ce45138da5247544e57.png

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.");
		}
	}
}

 

 

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值