Add 代码1

master
munvls9gi 3 years ago
parent 4cc9f83f8a
commit b007485017

@ -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();
}
}
}
Loading…
Cancel
Save