Java程序设计题目

Python017

Java程序设计题目,第1张

String

upString(String

s)对形参s进行大写转换,并返回转换后的字符串给调用者。

String

lowString(String

s)

对形参s进行小写转换,并返回转换后的字符串给调用者。

2)

main()方法:

public

static

void

main(String

args[])

{

String

s

BufferedReader

br=new

BufferedReader(InputStreamReader(System.in))

System.out.println(“请输入要转换的字条串:”)

s=br.readLine()

if(s!=null)

{

System.out.println(s+”转换为大写后为:”+Covert.upString(s))

System.out.println(s+”转换为小写后为:”+Covert.lowString(s))

}

else

System.out.println(“输入错误。”)

}

第一题看的脑壳疼,但是和第二题的意思差不多,我帮你做了第二题

public class List {

public static void main(String[] args) {

Employee e1 = new Employee("张强","2010/09/01",6890)

e1.show("普通")

System.out.println("年纳税:"+e1.tax())

Manager m1 = new Manager("朱慧","2003/07/06",18530,38000)

m1.show("管理")

System.out.println("年纳税:"+m1.tax())

}

}

//下面是补全的代码

class Employee{

String name,date

double salary,bonus

Employee(String name,String date,double salary){

this.name = name

this.date = date

this.salary = salary

}

public void show(String str){

System.out.println("岗位:"+str)

System.out.println("姓名:"+name+",入职时间:"+date+",月薪:"+salary)

}

public double tax(){

if(salary <= 0){

throw new RuntimeException("工资不允许小于等于0")

}

else if(salary>3000 && salary<=5000){

salary = salary*0.05*12 //纳税这里我也不知道他们具体是怎么个算法,反正意思差不多,套进去就行了

}

else if(salary>5000 && salary<=10000){

salary = salary*0.1*12

}

else if(salary>10000 && salary<=15000){

salary = salary*0.15*12

}

else if(salary>15000){

salary = salary*0.2*12

}

return salary+(bonus*0.2)

}

}

class Manager extends Employee{

Manager(String name,String date,double salary,double bonus){

super(name,date,salary)

super.bonus = bonus

}

public void show(String str){

System.out.println("岗位:"+str)

System.out.println("姓名:"+name+",入职时间:"+date+",月薪:"+salary+",奖金:"+bonus)

}

}

import java.io.BufferedInputStream

import java.io.BufferedOutputStream

import java.io.File

import java.io.FileInputStream

import java.io.FileNotFoundException

import java.io.FileOutputStream

import java.io.IOException

public class Test {

public static void main(String[] args) {

BufferedOutputStream out = null

try {

out = new BufferedOutputStream(new FileOutputStream(new File("d:/info.txt")))

String line = "第一行文本\n第二行文本"

out.write(line.getBytes())

} catch (FileNotFoundException e) {

e.printStackTrace()

} catch (IOException e) {

e.printStackTrace()

} finally {

if (out != null) {

try {

out.close()

} catch (IOException e) {

e.printStackTrace()

}

}

}

BufferedInputStream in = null

try {

in = new BufferedInputStream(new FileInputStream("d:/info.txt"))

StringBuffer buffer = new StringBuffer()

byte[] buff = new byte[in.available()]

while (in.read(buff) != -1) {

buffer.append(new String(buff))

}

System.out.println(buffer)

} catch (FileNotFoundException e) {

e.printStackTrace()

} catch (IOException e) {

e.printStackTrace()

} finally {

if (in != null) {

try {

in.close()

in = null

} catch (IOException e) {

e.printStackTrace()

}

}

}

}

}