while(score>=0){
num++;
sum+=score;
score=in.nextInt();
}
System.out.printf("学生总数为"+num+",平均分为"+sum/num);
根据封装的知识,编写Bus类的构造方法和方法
class Bus{
private String license;
private String brand;
public Bus(String license, String brand) {
if(license.length()!=8){
this.license="无";
}else {
this.license = license;
}
this.brand = brand;
}
public Bus() {
}
public String getLicense() {
return license;
}
public void setLicense(String license) {
if(license.length()!=8){
this.license="无";
}else {
this.license = license;
}
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public void print(){
System.out.println("车牌:"+license+",品牌:"+brand);
}
}
根据继承的知识,编写公司雇员类及其方法。
abstract class Employee{
private int id;
private String name;
public abstract void ShowMessage();
public Employee(int id, String name) {
this.id = id;
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
class SalesEmployee extends Employee{
private int salary;
public SalesEmployee(int id, String name, int salary) {
super(id, name);
this.salary = salary;
}
@Override
public void ShowMessage() {
System.out.println("工号:"+getId()+",姓名:"+getName()+",工资:"+salary);
}
}
class BasePlusSalesEmployee extends Employee{
private int baseSalary;
private int sales;
public BasePlusSalesEmployee(int id, String name, int baseSalary, int sales) {
super(id, name);
this.baseSalary = baseSalary;
this.sales = sales;
}
@Override
public void ShowMessage() {
System.out.println("工号:"+getId()+",姓名:"+getName()+",工资:"+(baseSalary+20*sales));
}
}
根据主程序需求,完成水果库存管理的程序。
Set<String> k=map.keySet();
int n=0;
for(String i:k){
System.out.println("水果:"+i+",库存:"+map.get(i));
n+=map.get(i);
}
System.out.println("当前水果总库存:"+n);