Tag: bluej

用Java覆盖用户库类

我使用BlueJ for Mac编写java代码。 我添加了stdlib.jar库(来自princeton http://introcs.cs.princeton.edu/java/stdlib/ )。 在添加这个库之前,我有自己的类名为StdDraw.java(我在项目中使用的特定类)并复制/粘贴代码。 我还调整了一些代码并添加了一些新行。 由于我无法编辑库代码,我如何覆盖或扩展库类以添加其他function?

检查密码

问题描述: 一些网站对密码强加了某些规则。 编写一个检查字符串是否为有效密码的方法。 假设密码规则如下: 密码必须至少包含八个字符。 密码仅包含字母和数字。 密码必须至少包含两位数字。 编写一个程序,提示用户输入密码,如果遵循规则则显示“有效密码”,否则显示“无效密码”。 这是我到目前为止: import java.util.*; import java.lang.String; import java.lang.Character; /** * @author CD * 12/2/2012 * This class will check your password to make sure it fits the minimum set requirements. */ public class CheckingPassword { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print(“Please enter […]

方法参数不匹配:必需double,不传递参数

我差不多完成但是当我编译时,我得到错误“在课程IncomeTax中的方法getUserTax不能应用于给定的类型;必需的double;找到:没有参数;原因:实际和正式的参数列表长度不同”我已经过了我的代码多次,我找不到错误的位置。 它接近“userTax = test.getUserTax();”行上代码的末尾。 import java.util.Scanner; //Needed for the Scanner Class /** * Write a description of class IncomeTax here. * * @author CD * 11/30/2012 * The IncomeTax class determines how much tax you owe based on taxable income. */ public class IncomeTax { private int income; /** * The constructor accepts an argument […]

Java嵌套循环

项目描述: 编写程序以打印21行大X形状的X,如下图所示。 确保两行在“11”行相交。 这是我想要的输出: 这是我到目前为止所拥有的。 public class Program168h { public static void main (String [] args) { String d= “X”; for (int a = 1; a = 1; b–) { System.out.print(” “); } System.out.print(d); for (int x = a; x < 22; x++) { System.out.print(" "); } System.out.print(d); System.out.println(); } } } 这只产生X的前半部分,我不知道如何产生下半部分。

int无法转换为int

新编程在这里,我不断得到错误信息,’不兼容的类型,int不能转换为int []’,问题是如果它们是相同的长度添加R1和R2,如果没有打印一条消息说’数组必须是相同的长度’,如果这很重要,不确定我哪里出错,任何帮助将不胜感激 public int[] arrayAdd(int[] R1, int[] R2) { int[] sumArray= new int[R1.length]; if( R1.length!= R2.length) { System.out.println(“The arrays must be same length”); } else { for(int i=0; i< R1.length; i++) for (int j=0; j<R2.length; j++) { sumArray= R1[i]+ R2[j]; // Error } } return sumArray; }

while循环在需要时不会结束

所以一些背景信息,我是编程的新手,我还在学习,所以我为我的琐碎错误制作道歉。 我正在制作自己的基于文本的游戏,以便进一步练习等。 以下是Dropbox上所有内容的链接,以获取更多信息: https : //www.dropbox.com/sh/uxy7vafzt3fwikf/B-FQ3VXfsR 我目前正在尝试为我的游戏实施战斗系统,并且我遇到了战斗序列的问题,在需要时没有结束。 “战斗序列”是一个while循环,如下所示: public void startCombat() { inCombat = true; while(inCombat != false)// && herohealth > 0 && monsterhealth > 0) { checkAlive(); heroHitMonster(); checkAlive(); monsterHitHero(); } attackinghero.setHeroHealth(herohealth); attackedmonster.setMonsterHealth(monsterhealth); } 其中checkAlive()方法如下: public void checkAlive() { if(herohealth <= 0) { System.out.println("You have died."); attackinghero.clearInventory(); inCombat = false; } else if(monsterhealth <= […]

bluej接口的eclipse插件

是否有Eclipse插件允许我们查看像BlueJ那样的类和对象? 我觉得在BlueJ中创建一个对象并测试它的方法比在Eclipse中更容易。我还在学习,但是程序员在实际项目中使用Bluej然后在Eclipse中导入代码,或者Bluej只是一个为学生要了解java的基础知识?

Java中的“int不能被解除引用”

我是Java的新手,我正在使用BlueJ。 我在尝试编译时不断得到“Int not be dereferenced”错误,我不确定问题是什么。 该错误特别发生在我底部的if语句中,其中“equals”是一个错误,“int不能被解除引用”。 希望得到一些帮助,因为我不知道该怎么做。 先谢谢你! public class Catalog { private Item[] list; private int size; // Construct an empty catalog with the specified capacity. public Catalog(int max) { list = new Item[max]; size = 0; } // Insert a new item into the catalog. // Throw a CatalogFull exception if the catalog […]