Bald bald bald bald 2022-02-13 07:15:28 阅读数:238
public Rectangle(){
this(5,6);
}
public Rectangle(int width, int length) {
this.width = width;
this.length = length;
}
public String toString(){
return "width=" + width + ",length=" + length;
}
import java.util.Scanner;
/* Your code will be embedded here */
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double w = input.nextDouble();
double h = input.nextDouble();
Rectangle myRectangle = new Rectangle(w, h);
System.out.println(myRectangle.getArea());
System.out.println(myRectangle.getPerimeter());
input.close();
}
}
class Rectangle{
double width = 1,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 (width+height)*2;
}
}
import java.util.*;
public class Main {
public static void main(String[] args) {
List <Book>books=new ArrayList<Book>();
Scanner in=new Scanner(System.in);
for(int i=0;i<5;i++)
{
String str=in.nextLine();
String []data=str.split(",");
Book book=new Book(data[0],Integer.parseInt(data[1]),data[2],Integer.parseInt(data[3]));
books.add(book);
}
System.out.println(totalprice(books));
}
/* Calculate all book Total price of */
public static int totalprice(List <Book>books)
{
int result=0;
for(int i=0;i<books.size();i++){
result+=books.get(i).getPrice();}
return result;
}
}
/* Please fill in the answer here */
class Book{
private String name,author;
private int price,date;
public String getName() {
return name;
}
public String getAuthor() {
return author;
}
public int getDate() {
return date;
}
public int getPrice() {
return price;
}
public void setName(String name) {
this.name = name;
}
public void setAuthor(String author) {
this.author = author;
}
public void setDate(int date) {
this.date = date;
}
public void setPrice(int price) {
this.price = price;
}
public Book(String name, int price,String author, int date) {
this.name = name;
this.author = author;
this.date = date;
this.price = price;
}
}
import java.util.Scanner;
class Student {
int id;
String name;
int age;
public Student(int id, String name, int age) {
this.id = id;
this.name = name;
this.age = age;
}
/* Please fill in the answer here */
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Student s1 = new Student(sc.nextInt(),sc.next(),sc.nextInt());
Student s2 = new Student(sc.nextInt(),sc.next(),sc.nextInt());
System.out.println(s1.equals(s2));
sc.close();
}
}
@Override
public boolean equals(Object obj) {
Student std = (Student) obj;
if(this.id == std.id) {
return true;
}else
return false;
}
import java.io.ObjectInputStream.GetField;
import java.util.Scanner;
class BankAccount{
int balance;
public int getBalance() {
return balance;
}
public BankAccount() {
this.balance = 0;
}
public BankAccount(int balance) {
this.balance = balance;
}
public int withdraw(int amount) {
return balance-=amount;
}
public int deposit(int amount) {
return balance+=amount;
}
}
public class Main{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int balance,amount1,amount2;
balance = input.nextInt();
int balance1 = balance;
amount1 = input.nextInt();
amount2 = input.nextInt();
BankAccount bankAccount = new BankAccount(balance);
int result1 = bankAccount.withdraw(amount1);
int result2 = bankAccount.deposit(amount2);
System.out.println(balance1 + "\n" + result1 + "\n" + result2);
}
}
class People{
protected String id;
protected String name;
/** The code you submit will be embedded here ( Replace this line ) **/
}
class Student extends People{
protected String sid;
protected int score;
public Student() {
name = "Pintia Student";
}
public Student(String id, String name, String sid, int score) {
super(id, name);
this.sid = sid;
this.score = score;
}
public void say() {
System.out.println("I'm a student. My name is " + this.name + ".");
}
}
public class Main {
public static void main(String[] args) {
Student zs = new Student();
zs.setId("370211X");
zs.setName("Zhang San");
zs.say();
System.out.println(zs.getId() + " , " + zs.getName());
Student ls = new Student("330106","Li Si","20183001007",98);
ls.say();
System.out.println(ls.getId() + " : " + ls.getName());
People ww = new Student();
ww.setName("Wang Wu");
ww.say();
People zl = new People("370202", "Zhao Liu");
zl.say();
}
}
public People(String id,String name) {
this.id = id;
this.name = name;
}
public People() {
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public void setId(String id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void say() {
System.out.println("I'm a person! My name is " + getName() + ".");
}
import java.util.Scanner;
import java.text.DecimalFormat;
abstract class shape {
// abstract class
/* Abstract method Find the area */
public abstract double getArea( );
/* Abstract method Seek perimeter */
public abstract double getPerimeter( );
}
/* The code you submit will be embedded here */
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
DecimalFormat d = new DecimalFormat("#.####");// Retain 4 Decimal place
double r = input.nextDouble( );
shape c = new Circle(r);
System.out.println(d.format(c.getArea()));
System.out.println(d.format(c.getPerimeter()));
input.close();
}
}
class Circle extends shape{
private double radius;
final double PI = 3.1415926535;
public double getRadius() {
return radius;
}
public Circle(double radius) {
this.radius = radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
@Override
public double getArea() {
return PI * radius * radius;
}
@Override
public double getPerimeter() {
return 2 * PI * radius;
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
Media[] ms = new Media[n];
for (int i=0; i<n; i++) {
String type = sc.next();
if (type.equals("book")) {
ms[i] = new Book(sc.next(), sc.nextDouble());
}else {
ms[i] = new DVD(sc.next());
}
}
double rent = MediaShop.calculateRent(ms, sc.nextInt());
System.out.printf("%.2f", rent);
}
}
/* Please fill in the answer here */
class Book extends Media{
String name;
double price;
Book(String name,double price) {
this.name = name;
this.price = price;
}
@Override
public double getDailyRent() {
return price*0.01;
}
}
class Media{
public double getDailyRent() {
return 0;
}
}
class MediaShop{
public static double calculateRent(Media[] medias,int days) {
double sum = 0;
for (int i = 0; i < medias.length; i++) {
sum += medias[i].getDailyRent()*days;
}
return sum;
}
}
class DVD extends Media{
String name;
public DVD(String name) {
this.name = name;
}
@Override
public double getDailyRent() {
return 1;
}
}
//Main Test class
public class Main{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double side1 = input.nextDouble();
double side2 = input.nextDouble();
double side3 = input.nextDouble();
Triangle triangle = new Triangle(side1, side2, side3);
String color = input.next();
triangle.setColor(color);
boolean filled = input.nextBoolean();
triangle.setFilled(filled);
System.out.println("The area is " + triangle.getArea());
System.out.println("The perimeter is "
+ triangle.getPerimeter());
System.out.println(triangle);
}
}
//GeometricObject class
class GeometricObject {
private String color = "white";
private boolean filled;
private java.util.Date dateCreated;
public GeometricObject() {
dateCreated = new java.util.Date();
}
public GeometricObject(String color, boolean filled) {
dateCreated = new java.util.Date();
this.color = color;
this.filled = filled;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public boolean isFilled() {
return filled;
}
public void setFilled(boolean filled) {
this.filled = filled;
}
public java.util.Date getDateCreated() {
return dateCreated;
}
@Override
public String toString() {
return "created on " + dateCreated + "\ncolor: " + color + "and filled: " + filled;
}
}
/* Please fill in the answer here */
class Triangle extends GeometricObject{
private double side1 = 1.0,side2 = 1.0,side3 = 1.0;
public Triangle() {
}
public Triangle(double side1, double side2, double side3) {
this.side1 = side1;
this.side2 = side2;
this.side3 = side3;
}
public double getSide1() {
return side1;
}
public double getSide2() {
return side2;
}
public double getSide3() {
return side3;
}
public void setSide1(double side1) {
this.side1 = side1;
}
public void setSide2(double side2) {
this.side2 = side2;
}
public void setSide3(double side3) {
this.side3 = side3;
}
public double getArea() {
double p = (side1 + side2 + side3) / 2;
return Math.sqrt(p*(p-side1)*(p-side2)*(p-side3));
}
public double getPerimeter() {
return side1 + side2 + side3;
}
@Override
public String toString() {
return "Triangle: side1=" + side1 + " side2=" + side2 +" side3=" + side3;
}
}
copyright:author[Bald bald bald bald],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/02/202202130715255976.html