Mid Term Exam 1 Name: ________
Multiple Choices
1. Programmer-named computer memory locations are called__B_ (1-A-5)
b. variables
c. addresses
d. appellation
C
(1-B-3)
‘ int add( int x, int y);
C ( 2-A-10)
char getCode(
char code)? C ( 2-A-10)
A ( 3-B-16)
a. 8
b. 6
c. 2
d. 3
13. Which of the following statements determines the square root of the number and
assigns it to the variable x? C
( 3-B-16)
a. number = squareRoot(x);
b. x = sqrt(number);
c. x = Math.sqrt(number);
d. number = Math.sqrtRt(x);
14. The date constructed with Data oneDay = new Date(2,3,4); is D ( 3-B-19)
a. Febuary 3, 2004
b. March 4, 2002
c. March 4, 1902
d. April 4, 1902
15. The date stored in a Date object is stored in __B ( 3-B-20)
a. seconds
b. milliseconds
c. minutes
d. years
Short Questions.
public class student1
{
public static void main(String[] args)
{
System.out.println("My name is Shin Liu");
System.out.println(" ID = 1234");
}
}
public class area
{
public static void main(String[] args)
{
int length = 10, width =5;
System.out.println("The area = " + length * width);
}
}
public class hamburger
{
private String size;
private double price;
void setSize(String s)
{
size = s;
}
String getSize( )
{
return size;
}
void setPrice(double p)
{
price = p;
}
double getPrice( )
{
return price;
}
}
public class testHam
{
public static void main(String[] args)
{
hamburger h1 = new hamburger();
h1.setSize("Large");
h1.setPrice(1.99);
System.out.println("The size " + h1.getSize());
System.out.println("The size " + h1.getPrice());
}
}
public class Interest
{
public static void main (String[] args)
{
double principle = 1000;
double rate = .05;
int rate1 = 5;
double money;
money = compute(principle,rate);
System.out.println("You get " + money );
money = compute(principle, rate1);
System.out.println("You get " + money);
}
public static double compute(double p, double r)
{
return (p * r);
}
public static double compute(double p, int r)
{
return ( p * r/100.0);
}
}