From b0074850171ac642290f438158421ef656ca1a63 Mon Sep 17 00:00:00 2001 From: munvls9gi <3233375157@qq.com> Date: Fri, 30 Jun 2023 05:27:55 +0800 Subject: [PATCH] =?UTF-8?q?Add=20=E4=BB=A3=E7=A0=811?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 代码1 | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 代码1 diff --git a/代码1 b/代码1 new file mode 100644 index 0000000..8f00298 --- /dev/null +++ b/代码1 @@ -0,0 +1,111 @@ +import java.util.Scanner; + +//股票类 + +class Stock{ + public String symbol; + public String name; + public double previousClosingPrice; + public double currentPrice; + Stock(String symbol,String name) + { + this.symbol = symbol; + this.name = name; + } + double changPercent() + { + return (currentPrice/previousClosingPrice)-1; + } +} + +public class Educode{ + public static void main(String[] args) { + Scanner input = new Scanner(System.in); + String symbol = input.next(); + String name = input.next(); + Stock stock = new Stock(symbol,name); + stock.previousClosingPrice = input.nextDouble(); + stock.currentPrice = input.nextDouble(); + System.out.printf("%s price changed: %.3f%%\n", stock.name,stock.changPercent()); + } +} + + + + +//传播媒体类 + +import java.util.Scanner; + +abstract class Media{ + private String id; + private String title; + private static String type = "Media"; + + Media(String id,String title) + { + this.id = id; + this.title = title; + } + String getId() { + return id; + } + String getTitle(){ + return title; + } + abstract void showInfomation(); + static void showType() + { + System.out.println("类型:"+type); + } +} + +class Book extends Media{ + private String press; + private String author; + Book(String id,String title,String press,String author){ + super(id,title); + this.press=press; + this.author=author; + } + String getPress(){ + return press; + } + String getAuthor(){ + return author; + } + @Override + void showInfomation(){ + System.out.println("ID: "+this.getId()+", Title: "+ this.getTitle()+ ", "+this.getPress()+", Author: "+this.getAuthor()); + } +} + + +class NewsPaper extends Media{ + NewsPaper(String id,String title){ + super(id,title); + } + void showInfomation(){ + System.out.println("ID: "+this.getId()+", Title: "+this.getTitle()); + } +} + +public class Educode{ + public static void main(String[] args) { + Media[] medias = new Media[2]; + Scanner input = new Scanner(System.in); + String id = input.nextLine(); + String title = input.nextLine(); + String press = input.nextLine(); + String author = input.nextLine(); + medias[0] = new Book(id,title,press,author); + id = input.nextLine(); + title = input.nextLine(); + medias[1] = new NewsPaper(id,title); + Media.showType(); + for (Media a : medias){ + a.showInfomation(); + } + } +} +