「java期中题目」java期中考试试题及答案
本篇文章给大家谈谈java期中题目,以及java期中考试试题及答案对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
java编程,这是期中考试成绩,无奈!
//一共有5个类 最后一个类是主类 我起名叫SalaryCounting,代码有点多,写了半个来小时呢,希望你能够满意,顺便我对你们老师的教学方法还有大脑的发育质量表示怀疑~!不明白为什么要弄的这么麻烦~!呵呵~!
每个类之间我都用长//////////////////////给你隔开了~!
abstract class Person {
private String name;
protected String post;
public Person(String name,String post){
this.setName(name);
this.post = post;
}
public String getID(){
return this.post;
}
public abstract double counting();
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
//////////////////////////////////////////////////////////////////
public class Leader extends Person{
private String name;//姓名
private String post;//职位
private int months;//干了几个月,不固定需要自己设置
private double monthsalary;//月薪自己设置多少就是多少
public Leader(String name, String post) {
super(name, post);
this.name = super.getName();
this.post = super.post;
}
public double counting() {
return getMonths()*getMonthsalary();
}
public void information(){
System.out.println("姓名:"+name+",职位:"+",月薪是:"+getMonthsalary()+",做了"+getMonths()+"个月的薪金是:"+counting());
}
public void setMonths(int months) {
this.months = months;
}
public int getMonths() {
return months;
}
public void setMonthsalary(double monthsalary) {
this.monthsalary = monthsalary;
}
public double getMonthsalary() {
return monthsalary;
}
}
/////////////////////////////////////////////////////////////////////
public class Management extends Person{
private String name;//姓名
private String post;//职位
private int basicsalary = 800;//基本工资是固定的为800
private double d;//津贴不固定需要自己设置
public Management(String name, String post) {
super(name, post);
this.name = super.getName();
this.post = super.post;
}
public double counting() {
return basicsalary+getD();
}
public void information(){
System.out.println("姓名:"+name+",职位:"+post+",基本工资:"+basicsalary+",津贴:"+getD()+",月工资为:"+counting());
}
public void setD(double d) {
this.d = d;
}
public double getD() {
return d;
}
}
//////////////////////////////////////////////////////////////////////
public class Teacher extends Person{
private String name;
private String post;
private double hours;
public Teacher(String name, String post) {
super(name, post);
this.name = super.getName();
this.post = super.post;
}
public double counting() {
if(this.post=="助教")//强烈鄙视,正规的写法比较连个字符串要用equals()方法,你们不是那么要求的我就这么写了
return 35.0*this.getHours();
else if(this.post=="讲师")
return 45.0*this.getHours();
else
return 55.0*this.getHours();
}
public void information(){
System.out.println("姓名:"+name+",职位:"+post+","+getHours()+"课时的工资为:"+counting());
}
public void setHours(double hours) {
this.hours = hours;
}
public double getHours() {
return hours;
}
}
/////////////////////////////////main入口类//////////////////////////
public class SalaryCounting {
public static void main(String args[]){
/////////////一个领导////////////////////////
Leader leader = new Leader("张三","领导");
leader.setMonths(10);
leader.setMonthsalary(2000);
leader.information();
//////////////////管理人员//////////////////////
Management m = new Management("李四","管理人员");
m.setD(1000);
m.information();
/////////////////////三种不同职位的老师///////////////////
Teacher one = new Teacher("王老师","助教");
one.setHours(100);
one.information();
///////////////////////////////////////////////
Teacher two = new Teacher("孙老师","讲师");
two.setHours(100);
two.information();
///////////////////////////////////////////////
Teacher three = new Teacher("东方老师","高级讲师");
three.setHours(100);
three.information();
}
}
///////javase基础群招人:71141421,欢迎
看看我的JAVA期中试题2
二. 选择题 (18题,共42分)。
(一)单选题(共12题,每题2分,共24分)。
程序设计语言的三种基本控制结构是:(B)
A. 输入、处理、输出 B. 顺序、选择、循环
C. 树形、网形、环形 D. 主程序、子程序、函数
在Java中,下列哪句话是正确的:(A )
A. 几个类可以写在一个文件里 B. 一个类可以写在几个文件里
C. 类的名称是不区分大、小写的 D. 方法的名称是不区分大、小写的
一个必须被继承的类要用哪个关键字来描述:(D )
A. static B. protected C. final D. abstract
下面程序的输出结果是:(D )
class DemoClass{
public static void main(String args[]){
int i=1,s=5;
do{
s += i;
i++;
}while(i 5);
System.out.println(“s=”+s); }}
A. s=0 B. s=5 C. s=10 D. s=15
下列方法method的定义正确的是(A)。
private int method () {char ch=’a’; return (int) ch; }
public void method {int a=8; return a;}
int method (int i ) {return (double) (i+10) ;}
method (int a) {return a;}哪一组都是Java关键字:( )
A. Student, float, main, public B. byte, boolean, box, float
C. long, extends, float, double D. classes, float, short, import
下面哪种说法是正确的: ( )
A. String是用来处理字符串的类,而B. StringBuffer不C. 是
D. StringBuffer是用来处理字符串的类,而E. String不F. 是
G. String和StringBuffer都是用来处理字符串的类
H. String和StringBuffer都不I. 是用来处理字符串的类
int x=1,a=0,b=0;
switch(x){
case 0: b++;
break;
case 1: a++;
break;
case 2: a++;b++;
break;
}
System.out.println("a="+a+",b="+b);
该程序的输出结果是 ( A)
A. a=1,b=0 B. a=1,b=1 C. a=1,b=2 D. a=2,b=2
下面哪个赋值语句是不合法的?
A、float a = 2.0 B、double b = 2.0
C、int c = 2 D、long d = 2
下面四组变量命名,符合JAVA变量命名规则的是(D )。
A. a@bc B. 6x C. void D. ye_78
定义类A及类中的方法getVar(),定义类A的子类B,若要在类B中覆盖类A的同名方法,下面正确的定义是( )
class A
{
private float x = 1.0f;
protected float getVar()
{return x;}
}
class B extends A
{
private float x = 2.0f;
//覆盖类A中的同名方法的代码放在此处}
float getVar(){return x;}
protected float getVar(float y){return x_y;}
protected float getVar(){return x;}
public float getVar(){return x;}
根据下面给出的代码,判断哪个叙述是正确的。(a )
public class Person {
static int arr[]=new int[10];
public static void main ( String a[] ) {
System.out.println ( arr[12] );
}
}
编译时将发生错误
编译时正确但是运行时出错
输出为0
输出为null
]
新手 丢人现眼了 还等高手来答答吧!!!!
Java 编程 期中考试题,请大家帮助
int temp1=0,temp2=5;//如果要更大的X,直接把temp2换为更大的数。
for(int x=0;xtemp2;x++){//第一个X。
for(int y=0;ytemp2;y++){
if(y==temp1 | y==temp2){
System.out.print("*");
}
else{
System.out.print(" ");
}
}
System.out.println("");//用于换行
temp1++;
temp2++;
}
temp1=0,temp2=5;//重置temp。
for(int x=0;xtemp2;x++){//第二个X。
for(int y=0;ytemp2;y++){
if(y==temp1 | y==temp2){
System.out.print(" ");
}
else{
System.out.print("*");
}
}
System.out.println("");//用于换行
temp1++;
temp2++;
}
//我打的是核心代码,你把它复制到主函数里面就好了!
关于java期中题目和java期中考试试题及答案的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
发布于:2022-11-24,除非注明,否则均为
原创文章,转载请注明出处。