东北大呲花题目

东北大呲花题目,第1张

PTA家电题目
interface ComputeWeight {
    double computeWeight();
}

class Television implements ComputeWeight{

    @Override
    public double computeWeight() {
        return 16.6;
    }
}


class AirConditioner implements ComputeWeight{

    @Override
    public double computeWeight() {
        return 40.0;
    }
}

class WashMachine implements ComputeWeight{
    @Override
    public double computeWeight() {
        return 60.0;
    }
}

class Truck {


    private ComputeWeight[] goods;

    public Truck(ComputeWeight[] goods) {
        this.goods = goods;
    }

    public double getTotalWeight() {
        double weight=0.0;
        for (int i = 0; i < goods.length; i++) {
            weight = weight + goods[i].computeWeight();
        }
        return weight;
    }
}
身份z排序
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int count=Integer.valueOf(sc.nextLine());
        String s[]=new String[count];
        for (int i=0;id2.getTime()){
                                temp=s[i];
                                s[i]=s[i+1];
                                s[i+1]=temp;
                            }
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                    }
                }
                for (int i=0;id2.getTime()){
                                temp=s[i];
                                s[i]=s[i+1];
                                s[i+1]=temp;
                            }
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                    }
                }
                for (int i=0;i
重复数据输出yes或no的问题
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner in=new Scanner(System.in);
        int a[]=new int[10005];//开辟数组去存储输入的数字
        int i=0,sign;//sign是是否出现重复数字的标识变量
        while(in.hasNext())//判断输入是否结束
        {
            a[i]=in.nextInt();
            i++;
        }
        sign=0;
        for(int f=0;f
统计指定字母开头的单词数量
import java.util.Scanner;

/**
 * 给出一句英文句子统计有多少个以某字母开头的单词
 * @author 佳哥
 *
 */

public class TestChar {
	public static void main(String[] args) {
		char words;
		String str;
		Scanner sc = new Scanner(System.in);
		words = sc.next().charAt(0);
		str = sc.nextLine();
		
		int count = 0;
		String[] strArray = str.split(" ");//把字符串通过" "(空格)拆分为字符串数组
		for (int i = 0; i < strArray.length; i++) {
			if(strArray[i].charAt(0) == words)   //if(strArray.startswitch(String.valueof(words)))
			{
				count++;
			}
		}
		System.out.println(count);

	}

}

设计一个矩形类Rectangle
class Rectangle {
    public double width=1;
    public double height=1;
    public Rectangle(){
    }
    public Rectangle(double width,double height){
        this.width=width;
        this.height=height;
    }
    public double getArea(){
        return width*height;
    }
    public  double getPerimeter(){
        return 2*(width+height);
    }
    
    
}
根据派生类写出基类
 public void say() {
        System.out.println("I'm a person! My name is " + this.name + ".");
    }

    public People(String id, String name) {
        this.id=id;
        this.name=name;

    }

    public People() {

    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
设计Worker类及其子类
class Worker {
    private double Rate;
   public  String name;
   public double salaried;
    public Worker(String name, double salaried) {
        this.name=name;
        this.salaried=salaried;
    }



    public void pay(int time){
        System.out.println("Not Implemented");
    }
}

class HourlyWorker extends Worker {

    public HourlyWorker(String name, double salaried) {
        super(name, salaried);
    }


    public void pay(int time){
        if (time>40){
            System.out.println((time-40)*2*salaried+40*salaried);
        }else {
            System.out.println(salaried*time);
        }

    }


    public void setRate(int i) {
        this.salaried=i;
        
    }
}
class SalariedWorker extends Worker {
    public SalariedWorker(String name, double salaried) {
        super(name, salaried);
    }

    public  void pay(){
        System.out.println("580.0");
    }
    public  void pay(int time){
        System.out.println("580.0");
    }

}
求圆面积自定义异常类
class Circle{
    double r;
    public  Circle(double r){
        this.r=r;
    }

    double area() throws CircleException {
        if(this.r<0){
            throw new CircleException(this.r);
        }
        return 3.14*r*r;
    }
}
class CircleException extends Exception{
    double r;
    public CircleException(double r)
    {
        super();
        this.r=r;
    }
    void print(){
        System.out.println("圆半径为"+this.r+"不合理");
    }

}

成绩录入时的及格与不及格人数统计
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int count=sc.nextInt();
        int pass=0;
        for (int i=0;i100){
                System.out.println(grade+"invalid!");
            }else if (grade>=60){
                pass++;
            }
        }
        System.out.println(pass);
        System.out.println(count-pass);
 
    }
}
 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/869016.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-13
下一篇 2022-05-13

发表评论

登录后才能评论

评论列表(0条)