By GokiSoft.com|
19:01 18/07/2022|
Java Basic
[Source Code] Hướng dẫn chữa bài examination - C2108L
https://docs.google.com/document/d/1c9iMqd97tw0t6CdrPLVo4k21FV8Nald5/edit
#DuluxePizza.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package question3;
/**
*
* @author std
*/
public class DuluxePizza extends Pizza{
String topping;
public DuluxePizza(String topping, double diameter, int numberOfSlice) {
super(diameter, numberOfSlice);
this.topping = topping;
}
@Override
public String toString() {
return topping + "\t" + super.toString();
}
}
#Main.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package question3;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
*
* @author std
*/
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter added toppings: ");
String addedToppings = in.readLine();
System.out.print("Enter diameter: ");
double diamter = Double.parseDouble(in.readLine());
System.out.print("Enter number of slices: ");
int slices = Integer.parseInt(in.readLine());
System.out.println("OUTPUT:");
Pizza p = new Pizza(diamter, slices);
System.out.println(p);
p = new DuluxePizza(addedToppings, diamter, slices);
System.out.println(p);
}
}
#Pizza.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package question3;
/**
*
* @author std
*/
public class Pizza {
double diameter;
int numberOfSlice;
public Pizza(double diameter, int numberOfSlice) {
this.diameter = diameter;
this.numberOfSlice = numberOfSlice;
}
@Override
public String toString() {
return diameter + "\t" + numberOfSlice;
}
}
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)