CS 160
Exam I
Spring 2005
|
Question Number |
Point Value |
Points Awarded |
|
1 |
15 |
|
|
2 |
20 |
|
|
3 |
14 |
|
|
4 |
16 |
|
|
5 |
15 |
|
|
6 |
20 |
|
|
Total |
100 |
|
Name _________________________
Student Id _______________________
<html>
<head>
<title>Spring 2005</title>
</head>
<body bgcolor="ffffff">
<center>
<h1>Midterm Test 1</h1>
</center>
<center>
<table width="75%"
border="5">
<tr>
<td align="right">
</td>
<td>
PERL
</td>
</tr>
<tr>
<td colspan="2" bgcolor="000000" align="center">
Python
</td>
</tr>
<tr>
<td colspan="2"
align="center">
<table width="50%">
<tr>
<td align="Center">Oberon</td>
<td align="center">Logo</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

int a = 5;
System.out.println(++a);
System.out.println(a++);
A *= 2;
System.out.println(a+5);
public class
{
private
int price;
private
String ride;
public
{
ride = r;
price = 10;
}
public
{
price = p;
ride = r;
}
public
{
price = 5;
ride = "Zipper";
}
public
String getName()
{
return ride;
}
public
String getName(String r)
{
DisneyLand d1 =
new
return
d1.getName();
}
public int takeRide(int
amnt)
{
int
cost;
cost = price * amnt;
return cost;
}
}
(2 points
each)
public class Fun
{
public
static void main(String [] args)
{
DisneyLand d1 =
new
String name = d1.getName();
DisneyLand d2 =
new
System.out.println(name + " and " + d2.getName());
DisneyLand d3 =
new
name =
d3.getName("It's a Small World");
System.out.println(name + " and " + d3.takeRide(2));
System.out.println(d3.getName() + " and " + d3.takeRide(3));
System.out.println(d1.takeRide(1)
+ ", " + d2.takeRide(2) + d3.takeRide(1));
}
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String answer = “hamburger”;
Use the API above and write the code to print out the amount of characters in the String answer. (Do not hardcode the 9, use the API and find it).
Here is a sample usage of creating an
instance of the Employee class and calling the methods, this is what I would
write if I was writing a program that uses the class you write from the
paragraph above. (sample):
Employee e1 = new Employee(5.75);
e1.work(5.25, 3);
e1.work(3.5, 1);
System.out.println(e1.getHours());
double cash =
e1.pay();
System.out.println("paid: " + cash);
Write your class here: