所以我的任务可能听起来很简单,但令我难以置信.我查看了互联网上的代码,但我无法掌握.我也不能掌握老师发布的幻灯片.这就是我的要求.
创建一个名为EmptyStackException的新运行时异常类型.
但是我不知道如何制作方法,类,变量或任何需要制作的东西以满足要求.我有几个类是DynamicArrayStack和LinkedStack的实现.Stack的接口.
任何指针都会非常有用.
谢谢
Mjall2
我有一个插件,可以向他们输入的电子邮件发送支持者推荐优惠券代码.当观众收到这封电子邮件时,我想创建一个流程,他们可以点击电子邮件中的"立即购物",优惠券将自动添加.
截至目前,对于"立即购买"按钮下的链接,我输入了以下内容:
websitename.biz/cart__trashed?code=DISCOUNTCODE
Run Code Online (Sandbox Code Playgroud)
要处理$code
我把它放在我的functions.php文件中:
add_action('woocommerce_before_cart', 'discount');
function discount( ) {
global $woocommerce;
$code= $_GET["code"];
if(!empty($code)){
if($woocommerce->cart->add_discount($code)){
echo '<div class="woocommerce_message"><strong>Applied coupon!</strong></div>';
}
}
}
Run Code Online (Sandbox Code Playgroud)
我面临的问题是:
我相信它是因为购物车是空的,代码不起作用.
只需要在受众点击链接时应用代码即可.
我怎样才能使这个工作?
我正在使用LRV(最近访问过的最少)算法制作一个程序.基本上,我设计了一个机器人遍历网格(这是一个2D字符数组)的算法.机器人在穿过网格时检查每个单元是EMPTY
(由'O' OCCUPIED
定义),(由'S' BLOCKED
定义)还是(由'X'定义).单元格只能被称为Sensor的对象占用(这有自己的类).BLOCKED
细胞无法遍历.每次机器人必须移动时,它接收来自传感器的方向.因此,在开始时,机器人将被放置在网格上并且它将丢弃传感器并从其获得方向,或者从预先存在的传感器获得方向.
现在我已经解释了我的程序,我的具体问题是,我有一个类Sensor,它有一个getVisitingDirection
返回INT 的方法.我有一个每个方向的计数器(INT类型的北,南,东和西)这是班级.
package ITI1121A;
public class Sensor {
private int cColumns;
private int cRows;
private int North;
private int South;
private int West;
private int East;
public Sensor(int sX, int sY) {
cColumns = sX;
cRows = sY;
South= -1;
North = -1;
West = -1;
East = -1;
}
/* ADD YOUR CODE HERE */
public int getX ()
{return cColumns;}
public int getY ()
{return cRows;}
public …
Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个名为Concentration的存储卡匹配游戏.到目前为止,我有3个班级.内存扩展JFrame实现了ActionListener
Board扩展了JPanel实现的ActionListener
Cell扩展了JButton
到目前为止,我已经实现了一个弹出窗口.使用列表添加成对的单元格类型.在我的董事会中随机分配所有单元格.显示所有单元格的背面(img)(有24个单元格,4行6列).现在当我点击我的卡片时,我得到一张白色图片.目前作为一个短期目标,我想要实现的是,当我点击一个按钮时,相应的图像显示在按钮上.
我在类Board中以这种方式实现了ActionPerformed.
public void actionPerformed(ActionEvent e){
if(e.getSource() instanceof Cell){
Cell temp = (Cell)e.getSource();
temp.setSelected(true);
if (temp.selected()){
int row = temp.getRow();
int column = temp.getColumn();
board[row][column].setIcon2();
}
}}
Run Code Online (Sandbox Code Playgroud)
我的set selected方法仅用于将Cell类中的布尔变量的值更改为true.这是我在类Cell中的setIcon2方法.
public void setIcon2(){
ImageIcon x = new ImageIcon();
x = getImageIcon();
setIcon(x);
}
Run Code Online (Sandbox Code Playgroud)
这是Cell类中的getImageIcon方法.
private ImageIcon getImageIcon() {
int temp=0;
int id;
if (localSelected) {
id = getType();
String tempId = Integer.toString(id);
icons[temp] = new ImageIcon("img-" + tempId + ".jpg");
temp++;
return icons[temp];
} else {
id = …
Run Code Online (Sandbox Code Playgroud) 我目前是一名学生,他的作业涉及将二叉树方法调整为通用树方法。我唯一的问题是,我对以下通用树的后序遍历是否正确?如果是这样,那么我知道我的算法正在工作,我只是无法正确掌握后序遍历的窍门,我觉得并认为该网站可以提供帮助。
B
--------------------|------------------
| | |
A ------D----- ---I---
| | | | |
C E G H L
|
F
Run Code Online (Sandbox Code Playgroud)
我的结果是:ACEFGDHLIB
我有一个方法,返回一个类型SENSOR在粗体是我得到一个运行时NullPointerException,无法理解为什么.
public Sensor getSensorAt(int x,int y,GridMap grid)
{
/*go through sensor storage array
* for eachsensor index call the get x get y method for that
* compare it to the x,y of the robot
*
*/
for(int i=0;i<s1.length;i++){
if(s1[i].getX() == x){ <======= NullpointerException
if(s1[i].getY()== y){
return s1[i];
}
}
}
return null;
}
Run Code Online (Sandbox Code Playgroud)