日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

SCAU 计算钢板的利用率

發布時間:2024/5/14 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SCAU 计算钢板的利用率 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

作業4:計算鋼板的利用率
題目類別: B作業

關鍵字: 接口 類 繼承 實現 多態

內容要求:

  • 問題描述:
  • 某工廠需要在矩形的鋼板上截取不同形狀來制作零件。截取形狀過程中需要記錄形狀類型及可以計算形狀面積的必要數據。

    首先記錄鋼板的大小:寬度和高度

    目前的形狀有:

    矩形,類型用字符A表示,記錄數據為寬度和高度

    圓形,類型用字符B表示,記錄數據為半徑

    梯形,類型用字符C表示,記錄數據為上底寬、下底寬和高度

  • 編寫Java應用程序根據記錄的數據計算鋼板和利用率。要求如下:
  • (1) 從鍵盤讀取數據,鍵盤輸入數據格式為:

    第一行是兩個實數,表示鋼板的寬度和高度;

    以后每一行代表一個形狀的數據,包括類型及計算面積的數據

    例如:

    2000 1000

    A 20 30

    B 30

    B 45.5

    C 10 30.5 15

    A 10 40

    (2) 根據輸入的數據計算并輸出該鋼板的利用率。

    (3) 采用面向抽象的編程方式,基于抽象類或接口進行編程。

    (4) 程序具有較好的擴展性,例如增加一種形狀三角形(類型符為D,記錄三角形的三條邊長)時,計算利用率的代碼不會被修改。

    總結:
    1.這是用了一個Calculation接口
    2.這里換行結束我查了很久的一種辦法就是:

    import java.io.IOException; import java.io.InputStreamReader; String kinds = ""; BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); kinds = bf.readLine(); if (kinds.length() == 0)

    Main

    // // Source code recreated from a .class file by IntelliJ IDEA // (powered by FernFlower decompiler) //package com.company;import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner;public class Main {public Main() {}public static void main(String[] args) throws IOException {System.out.println("請分別輸入鋼板的長和寬");Scanner cin = new Scanner(System.in);BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));SteelPlate s = new SteelPlate(cin.nextDouble(), cin.nextDouble());double using = 0.0D;while(true) {System.out.println("請輸入A/B/C (輸入回車即結束):");String kinds = "";kinds = bf.readLine();if (kinds.length() == 0) {System.out.println("利用率為:" + using / s.getArea() * 100.0D + "%");return;}if (kinds.charAt(0) == 'A') {System.out.println("請分別輸入矩形的寬和高:");Rectangle r = new Rectangle(cin.nextDouble(), cin.nextDouble());using += r.getArea();} else if (kinds.charAt(0) == 'B') {System.out.println("請輸入圓形的半徑:");Circle c = new Circle(cin.nextDouble());using += c.getArea();} else if (kinds.charAt(0) == 'C') {System.out.println("請輸入梯形的上邊和下邊和高:");Trapezoid t = new Trapezoid(cin.nextDouble(), cin.nextDouble(), cin.nextDouble());using += t.getArea();}}} }

    Calculation接口

    // // Source code recreated from a .class file by IntelliJ IDEA // (powered by FernFlower decompiler) //package com.company;public interface Calculation {double PI = 3.14D;double getArea();double getUtilizationRate(double var1); }

    Circle

    package com.company;public class Circle implements Calculation{private double radius;public Circle(double radius) {this.radius = radius;}public double getRadius() {return radius;}public void setRadius(double radius) {this.radius = radius;}@Overridepublic double getArea(){return radius*PI*radius;}@Overridepublic double getUtilizationRate(double steelArea) {return getArea()/steelArea;}}

    Rectangle

    package com.company;public class Rectangle implements Calculation{private double width;public Rectangle(double width, double height) {this.width = width;this.height = height;}public double getWidth() {return width;}public void setWidth(double width) {this.width = width;}public double getHeight() {return height;}public void setHeight(double height) {this.height = height;}public double height;@Overridepublic double getArea(){return width*height;}@Overridepublic double getUtilizationRate(double steelArea) {return getArea()/steelArea;}} package com.company;public class Trapezoid implements Calculation{private double top;private double bottom;public double getTop() {return top;}public void setTop(double top) {this.top = top;}public double getBottom() {return bottom;}public void setBottom(double bottom) {this.bottom = bottom;}public double getHeight() {return height;}public void setHeight(double height) {this.height = height;}public Trapezoid(double top, double bottom, double height) {this.top = top;this.bottom = bottom;this.height = height;}@Overridepublic double getArea(){return (top+bottom)*height/2;}@Overridepublic double getUtilizationRate(double steelArea) {return getArea()/steelArea;}public double height; } package com.company;public class SteelPlate {private double width;private double height;public double getWidth() {return width;}public SteelPlate(double width, double height) {this.width = width;this.height = height;}public void setWidth(double width) {this.width = width;}public double getHeight() {return height;}public void setHeight(double height) {this.height = height;}public double getArea(){return this.width*this.height;} }

    總結

    以上是生活随笔為你收集整理的SCAU 计算钢板的利用率的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。