Quiz 4
There were three different versions of the quiz distributed, so you'll
have to find your answers in each of these.
Problem 1 (8 points)
public boolean action (Event e, Object obj)
{
if (e.target == b1)
{
sw = swField.getString();
i1 = sw.length();
i1Field.setInt(i1);
return true;
}
return true;
}
public boolean action (Event e, Object obj)
{
if (e.target == b1)
{
sw = swField.getString();
sw = sw + "#";
swField.setString(sw);
return true;
}
return true;
}
public boolean action (Event e, Object obj)
{
if (e.target == b1)
{
i1 = iField.getInt();
i1 = i1 + 10;
i1Field.setInt(i1);
return true;
}
return true;
}
Problem 2 (4 points)
People had a lot of trouble with the array/loop problem, so we reduced
it's value. Be sure to review this before the midterm.
if (ddd[i]==k1)
{
count = count + 1;
}
if (d1[i]==k)
{
d1[i] = d1[i] + 1;
}
if (key==dd[i])
{
keyind = i;
}
Problem 3 (8 points)
Here, some people tried to use things like StringField's and action
routines. This class is not an applet, so those things shouldn't be
used.
public class Book
{
protected String author;
protected String title;
protected double price;
public Book (String a1, String t1)
{
author = a1;
title = t1;
}
public void setAuthor(String aaa)
{
author = aaa;
}
public void fixAuthor()
{
author = "Dr." + author;
}
}
public class Book
{
protected String author;
protected String title;
protected double price;
public Book (String tt)
{
title = tt;
}
public void setAuthor(String aa)
{
author = aa;
}
public void fixAuthor()
{
author = author.substring(1,author.length());
}
}
public class Book
{
protected String author;
protected String title;
protected double price;
public Book (String a1)
{
author = a1;
}
public void setTitle(String t1)
{
title = t1;
}
public void fixTitle()
{
title = title.substring(0,title.length()-1);
}
}