- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我刚刚进行了一个测验,我们应该根据一些给定的标准创建一个医院类,然后在 HospitalTester 驱动程序类中实例化一个医院类...我在 IntelliJ 中顺利完成了作业,并且运行良好。
然后我做了我一直做的事情,我将要提交的java文件HospitalTester.java
从项目文件夹中复制出来,然后单独提交(教授没有希望我们提交项目,只是单独的 java 文件)。
我以为我已经完成了,一切都很好,但令我恐惧的是,我今天收到一封电子邮件,说类只有 1 人获得了 100/100。我去检查我提交的内容,当我运行它时,没有任何反应......
我的所有代码都在下面,当我将其作为保存为“Quiz 1”的项目打开时,它运行得很好,但当我从项目文件夹的 src 文件夹中删除它时,它无法运行。
为什么会发生这种情况?
import java.text.DecimalFormat;
import java.util.Scanner;
public class HospitalTester {
public static void main(String[] args) {
// Construct new hospital instance
Hospital hospital = new Hospital(
"Grey-Sloan Memorial",
10,
150000.79,
2450896.50);
// Asks for keyboard prompt for hospital information.
hospital.setName();
hospital.setNumberOfDoctors();
hospital.setAvgDoctorSalary();
hospital.setTotalGrossIncome();
//Creates a new String variable to print toString() method out from
String sys;
sys = hospital.toString();
System.out.print(sys);
// Provides percent of doctor salary compared to Total Gross Income
hospital.percentDoctors();
}
}
class Hospital {
String name;
private int number_doctors;
private double avg_salary_doctors;
private double total_gross_income;
// Hospital Constructor
public Hospital(String name, int number_doctors, double avg_salary_doctors, double total_gross_income) {
this.name = name;
this.number_doctors = number_doctors;
this.avg_salary_doctors = avg_salary_doctors;
this.total_gross_income = total_gross_income;
}
// Get methods to return hospital name, number of doctors, avg doctor salary, and total gross income of hospital.
public String getName() {
return name;
}
public int getNumberOfDoctors() {
return number_doctors;
}
public double getAvgDoctorSalary() {
return avg_salary_doctors;
}
public double getTotalGrossIncome() {
return total_gross_income;
}
//Set methods to change hospital name, number of doctors, avg doctor salary, and total income of hospital varaibles.
public void setName() {
System.out.print("Enter a new name for the hospital: \n");
this.name = new Scanner(System.in).nextLine();
}
public void setNumberOfDoctors() {
System.out.print("Enter the number of doctors working at the hospital: \n");
this.number_doctors = new Scanner(System.in).nextInt();
}
public void setAvgDoctorSalary() {
System.out.print("Enter the average doctor salary: \n");
this.avg_salary_doctors = new Scanner(System.in).nextDouble();
}
public void setTotalGrossIncome() {
System.out.print("Enter the total gross income that the hospital makes: \n");
this.total_gross_income = new Scanner(System.in).nextDouble();
}
// Calculates total doctors salary: (Number of doctors * avg salary of doctor) / Total Gross Income
public void percentDoctors() {
double percent, percent_converted;
String percent_converted_rounded;
percent = (number_doctors * avg_salary_doctors) / total_gross_income;
percent_converted = percent * 100;
// Round off to two decimal places.
DecimalFormat df = new DecimalFormat("#,###,##0.00");
percent_converted_rounded = df.format(percent_converted);
System.out.print("Doctor salary as a percent of total gross income = " + percent_converted_rounded + "% \n");
}
public String toString() {
//Provide formatting to Doctor salary and hospital income financial numbers.
DecimalFormat df = new DecimalFormat("#,###,##0.00");
String hospital_income_format, avg_salary_doctors_format;
hospital_income_format = df.format(total_gross_income);
avg_salary_doctors_format = df.format(avg_salary_doctors);
return "Name = " + name
+ "\nNumber of Doctors = " + number_doctors + " doctors " +
"\nAverage Doctor Salary = $" + avg_salary_doctors_format +
"\nHospital Income = $" + hospital_income_format + "\n";
}
}
最佳答案
我刚刚将您的代码复制到一个名为 HospitalTester.java
我运行javac HospitalTester.java
我运行java HospitalTester
扫描仪启动:
Enter a new name for the hospital:
希望有帮助。
关于Java 类文件在 IntelliJ 项目中运行,但不在项目之外运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54909360/
我一直在尝试运行 junit 测试,但不断面临这个问题。我试图在互联网上寻找答案,但没有任何帮助。 ] 1 最佳答案 我遇到了同样的问题,但已通过更新 Intellij 最新版本 2020.3 解决。
我知道这个问题以前曾以各种形式提出过,但我已经检查了所有答案,我认为我们已经排除了所有答案。 错误: java.lang.NoClassDefFoundError: com/lgc/infra/geo
TL; 博士 我如何导入 com.intellij.psi.JavaPsiFacade我的 IntelliJ 插件中的类? 背景资料 我正在尝试开发一个 IntelliJ 插件。我一直在遵循入门指南
我目前正在为 IntelliJ 开发一个插件,并尝试使用另一个内置的 IntelliJ 插件作为依赖项 (git4idea)。如 IntelliJ 插件开发文档中所述,我将所需的 JAR 添加到项目结
我尝试在 MacOS 上安装与 IntelliJ 10 集成的 JProfiler。安装程序试图找到我没有的“IntelliJ 配置文件夹”,我也不知道如何创建。 任何帮助或提示都会很棒。 最佳答案
我记得有一个选项可以在失去对idea windows 的关注时自动构建当前项目(例如,您从intellij 切换到浏览器以测试您的webapp),但是我找不到(idea 12.1.6)。 你知道我在哪
我有两个 Java 项目作为 Bukkit/Spigot 插件。两个项目都使用 gradle、私有(private)存储库,一个项目应该从另一个项目继承。 项目: SpigotCore - 包含数据库
标题说明了一切……只是想让 Glassfish 继续前进。这是我得到的错误 Detected server admin port: 4848 [2015-04-06 07:37:56,138] Art
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 7 年前。 Improve t
每次我重新启动系统或安装新插件时,我的 intellij 键盘映射都会重置。如果重要的话,我正在开发容量非常有限的 win XP - 只有 1 个 25 GB 容量的驱动器。但是,仍有 7 GB 的可
这是一段简单代码的输出: /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/bin/java "- javaagent:/Applic
Intellij Idea的状态栏中是否显示选中的行数? (如果选择包括单词,则显示“字符数”选择计数) 最佳答案 评论中提到的功能现已可用。 右击状态栏,选择“行列数”,见图: 然后您在状态栏中看到
我想将大量代码重构到新类中。我需要一个工具来让我将部分旧代码标记为“已完成”,这样我就可以看到还剩下什么要做。 我把它想象成背景或边缘的一些颜色。如果我可以使用不同的颜色或向代码块添加注释,那将是最好
如何查找和排序 TODO项目按字母顺序排列,就像在 Eclipse 中一样? 我不能使用文件搜索功能,因为我只需要查找注释而不是字符串和文字。对于当前混合的源文件/模板/脚本,TODO 至少已经以下列
我正在使用 IntelliJ Idea 开发一个 Spring 项目。我想知道是否有办法从 IntelliJ 日志或其他一些黑暗的方式知道我在这个项目上花了多少时间? 我是在看到 Idea 的 Pro
当您有 todo:在您的评论中,intellij 可以检测到它并将其显示在待办事项列表中。我怎样才能让一些自定义标记被识别?例如,config: . 最佳答案 在“设置”中查看“编辑器”/“待办事项”
我已启用所有 soft wrap可以在 Intellij (2017.3) 中找到的设置: Appearance|General同意该 list : 我点击了“应用”——这通常实际上可以立即查看效果—
我需要调查微服务中的内存泄漏。我看到一些 Profile... Intellij 中的菜单项 单击它后,应用程序将运行。你能告诉我在哪里可以看到分析的结果吗? 最佳答案 此操作用于分析 Android
我将 IntellIJ 安装更新到最新版本 (11.1.4),现在没有出现编辑器窗口。双击文件,跳转到源代码,没有任何 react 。没有错误消息,只是没有出现。如果我双击一个 xml 布局文件,预览
有没有办法在项目中自动构建工件,就像它如何自动构建输出一样?如果存在快捷键也可以使用 -- 现在我需要单击 Build -> Build Artifacts -> Build这很麻烦。 编辑:在这种情
我是一名优秀的程序员,十分优秀!