我是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 is full.
public void insert(Item obj) throws CatalogFull {
if (list.length == size) {
throw new CatalogFull();
}
list[size] = obj;
++size;
}
// Search the catalog for the …Run Code Online (Sandbox Code Playgroud) 仅供参考我编程Java在BlueJ.
我对这门语言比较陌生,我在排序方面遇到了麻烦.
我试图调用/测试主类中的所有5种排序方法.
我想出了如何调用/测试Quicksort:
Sorting.quickSort(friends, 0, friends.length-1);
Run Code Online (Sandbox Code Playgroud)
但其他人工作不正常.特别是这些:
Sorting.mergeSort(friends, 0, friends.length-1);
Sorting.PbubbleSort(friends, 0, friends.length-1);
Sorting.PinsertionSort(friends, 0, friends.length-1);
Sorting.selectionSort(friends, 0, friends.length-1);
Run Code Online (Sandbox Code Playgroud)
希望有人可以帮助我.
作为参考,这是未排序时的输出:
Smith, John 610-555-7384
Barnes, Sarah 215-555-3827
Riley, Mark 733-555-2969
Getz, Laura 663-555-3984
Smith, Larry 464-555-3489
Phelps, Frank 322-555-2284
Grant, Marsha 243-555-2837
Run Code Online (Sandbox Code Playgroud)
这是排序时的输出:
Barnes, Sarah 215-555-3827
Getz, Laura 663-555-3984
Grant, Marsha 243-555-2837
Phelps, Frank 322-555-2284
Riley, Mark 733-555-2969
Smith, John 610-555-7384
Smith, Larry 464-555-3489
Run Code Online (Sandbox Code Playgroud)
这是课程Sorting,我应该注意这是正确的:
public class Sorting{
/**
* Swaps …Run Code Online (Sandbox Code Playgroud) 我很新Java,我正在使用BlueJ.我一直收到错误:
method find in class Catalog cannot be applied to given types;
required: int
found: Item
reason: actual argument Item cannot be converted to int by method invocation conversion
Run Code Online (Sandbox Code Playgroud)
我很困惑,反过来又不确定如何解决问题.希望有人可以帮助我.先感谢您.
这是我的Program2类:
import java.util.*;
public class Program2 {
public static void main(String[] args) {
Scanner kbd = new Scanner(System.in);
Catalog store = new Catalog(3);
int itemnum;
Item item;
try {
store.insert
(new Music(1111, "Gold", 12.00, "Abba"));
store.insert
(new Movie(2222, "Mamma Mia", 16.00, "Meryl Streep"));
store.insert
(new Book(3333, …Run Code Online (Sandbox Code Playgroud) 我对Scheme很新,我正在使用DrRacket,我希望得到一些急需的帮助.
我正在定义结构,我在某种程度上理解,但我似乎遇到了障碍.
我需要做到这一点,因此"EmployeeRaise"函数适用于所有检查期望,而不会使它只能用于一个特定的检查期望.
主要问题是在定义中,更具体地说,在粗体部分,
(+(员工 - 小时率em)(*(员工 - 小时率em)0.1)))
我似乎无法弄清楚它如何确定每个人的员工每小时费率,而不是那个用"em"定义的员工.
我认为将所有三名员工都定义为"em",但不会让我这样做.
我希望有人可以帮助我.
这是我的代码:
(define-struct employee (Name Hourly-rate overtime?))
;;Signature: EmployeeRaise: string -> number
;;Purpose: Consumes an employee and returns an employee with the hourly rate increased by 10%.
;;Tests
(check-expect (EmployeeRaise "Ben") 13.2)
(check-expect (EmployeeRaise "Joe") 16.5)
(check-expect (EmployeeRaise "Debbie") 22)
;; Define
(define (EmployeeRaise employee-Name)
(+ (employee-Hourly-rate em) (* (employee-Hourly-rate em) 0.1)))
Run Code Online (Sandbox Code Playgroud)