java 考试题 请求各位大神帮个忙 能答多少 答多少 人多力量大 谢谢大家了。!!

1) Write a method that receives two int parameters and returns the smaller
of the two values. Call your method getSmaller.
2) Write a method that receives two String objects and returns true if the
two Strings start with the same character (ignoring case) and false
otherwise.
3) Using the Die class, write a method that will use two Die, roll them
100 times and return the number of times that the sum of the two is
7 or 11.
For questions 4 and 5, write the requested portions of a class called Employee.
4) An Employee will have a name, social security number, position, and
hourly wages. Define the instance data for this class.
5) Write a method that is passed the int value of the number of hours worked
for the week as a parameter, and returns the pay for the Employee,
including overtime, which is 1.5 * hourly wages for each hour over 40.
1) The behavior of an object is defined by the object’s
a) instance data
b) constructor
c) visibility modifiers
d) methods
e) all of the above
2) The relationship between a class and an object is best described as
a) classes are instances of objects
b) objects are instances of classes
c) objects and classes are the same thing
d) classes are programs while objects are variables
e) objects are the instance data of classes
3) To define a class that will represent a car, which of the following definitions is
most appropriate?
a) private class car
b) public class car
c) public class Car
d) public class CAR
e) private class Car

4) Which of the following reserved words in Java is used to create an instance of a class?
a) class
b) public
c) public or private, either could be used
d) import
e) new

答题完毕,代码全部测试通过。
本人英语一般,欢迎追问。

1)
int getSmaller(int a, int b) {return a<b? a:b;}

2)
boolean startSame(String a,String b){
String s1=a.substring(0, 1);
String s2=b.substring(0, 1);
if(s1.equalsIgnoreCase(s2))
return true;
else return false;
}

3)
//假设Die类如下
class Die{
int roll(){
return (int)(Math.random()*1000%5+1);
}
}

//则method为:
int rollTwo(Die a,Die b){
int count=0,sum=0;
for(int i=0;i<100;i++){
sum=a.roll()+b.roll();
if(sum==7||sum==11)
count++;
}
return count;
}

4)
class Employee{
String name,position;//本人假设position代表职位
long number;
int hourlyWage;
}

5)
double wage(int hours){
if(hours<=40)
return hours*hourlyWage;
else
return 40*hourlyWage+(hours-40)*hourlyWage*1.5;
}

补充:
1) d
2) b
3) c
4) e

望采纳。答得很辛苦,给点分吧。
温馨提示:答案为网友推荐,仅供参考
相似回答