7-6 sdut- JAVA-Overall Project Cost
分数 12
全屏浏览
切换布局
作者 马新娟
单位 山东理工大学
You are required to write a Java application program to determine and display the overall cost of a project. The overall cost of a project is made up of a fixed cost and a variable cost. Each project has a fixed cost of €10,000 and depending on the project category and the service type a variable cost is added. To determine the variable cost of a project, your program should accept a project category and a service type from the end user and depending on their values, determine the variable cost of the project based on the data in Table 1. A valid project category is one of 1, 2 or 3. If the user does not supply a valid project category an appropriate error message should be displayed and your program should end. The appropriate error message should be “Invalid project category: project category should be in the range 1 to 3“. If the user supplies a valid project category he/she should then be requested to enter a key service type. A valid service type is one of 1, 2 or 3. If the user supplies and invalid key service type an appropriate error message should be displayed and your program should end. The appropriate error message should be “Invalid service type: service type should be in the range 1 to 3“ If a valid service type is supplied then your program should determine the overall cost and display it.
Input Specification:
the project category and the service type .
Output Specification:
display the overall cost of a project.
Sample Input:
2 3
Sample Output:
Project cost is: 23500.0
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
栈限制
8192 KB
import java.util.Scanner; public class Main{ public static void main(String [] args) { Scanner sc=new Scanner(System.in); double[][] a = {{5600.50, 5500.00, 6000.00}, {10600.50, 11000.00, 13500.00}, {17000.00, 22000.00, 25000.00}}; int n;int t; n=sc.nextInt(); if(n==1||n==2||n==3) { t=sc.nextInt(); if(t==1||t==2||t==3) { System.out.println("Project cost is: "+(a[n-1][t-1]+10000)); } else{ System.out.println("Invalid service type: service type should be in the range 1 to 3"); } } else { System.out.println("Invalid project category: project category should be in the range 1 to 3"); } } }