《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》,点击传送门,即可获取!
}
=================================================================
package dishisanzhang;
import java.util.ArrayList;
import java.util.Arrays;
public class dishisanzhang {
public static void main(String[] args) {
// TODO Auto-generated method stub
Integer[] n = {1, 5, 6, 4, 3, 2};
ArrayList list = new ArrayList<>(Arrays.asList(n));
sort(list);
System.out.println(list);
}
public static void sort(ArrayList list){
Number tmp; //下面是一个冒泡排序
for(int i=0;i<list.size()-1;i++)
for(int j=0;j<list.size()-i-1;j++)
if((int)(list.get(j+1))<(int)(list.get(j))){
tmp = list.get(j);
list.set(j, j+1);
list.set(j+1, tmp);
}
}
}
=================================================================
看清单!
=================================================================
package dishisanzhang;
import java.util.Date;
public abstract class GeometricObject implements Comparable< GeometricObject >{
private String color;
private boolean filled;
private Date dateCreated;
protected GeometricObject(){
dateCreated = new Date();
}
protected GeometricObject(String color,boolean filled){
this.color = color;
this.filled = filled;
dateCreated = new Date();
}
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 Date getDateCreated(){
return dateCreated;
}
@Override
public String toString(){
return “Create on “+dateCreated+”\nColor: “+color+”\n and Filled”+filled;
}
@Override
public int compareTo(GeometricObject o){
if (getArea() < o.getArea())
{
return -1;
}
else if (getArea() > o.getArea())
{
return 1;
}
else
return 0;
}
public static GeometricObject max(GeometricObject o1,GeometricObject o2){
if (o1.compareTo(o2) > 0)
{
return o1;
}
else
return o2;
}
public abstract double getArea();
public abstract double getPerimeter();
}
package dishisanzhang;
public class Rectangle extends GeometricObject {
private double width;
private double height;
public Rectangle() {
}
public Rectangle(double width, double height) {
this(width, height, “white”, false);
}
public Rectangle(double width, double height, String color, boolean filled) {
super(color, filled);
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;
}
@Override
public double getArea() {
return width * height;
}
@Override
public double getPerimeter() {
return 2 * (width + height);
}
@Override
public String toString() {
return "\nRectangle Width: " + getWidth() + " and Height: " + getHeight();
}
}
package dishisanzhang;
public class Circle extends GeometricObject {
private double radius;
public Circle() {
}
public Circle(double radius) {
this(radius, “white”, false);
}
public Circle(double radius, String color, boolean filled) {
super(color, filled);
this.radius = radius;
}
public double getRadius() {
return radius;
}
@Override
public double getArea() {
return radius * radius * Math.PI;
}
@Override
public double getPerimeter() {
return 2 * radius * Math.PI;
}
@Override
public String toString() {
return "\nCircle Radius : " + getRadius();
}
}
package dishisanzhang;
public class dishisanzhang {
public static void main(String[] args) {
// TODO Auto-generated method stub
Rectangle r1 = new Rectangle(1,2);
Rectangle r2 = new Rectangle(2,3);
System.out.println("The Max: "+GeometricObject.max(r1, r2));
Circle c1 = new Circle(2);
Circle c2 = new Circle(3);
System.out.println("The Max: "+GeometricObject.max(c1, c2));
}
}
=================================================================
package dishisanzhang;
public class Circle {
private double radius = 1.0;
public Circle() {
radius = 1.0;
}
public Circle(double radius) {
this.radius = radius;
}
public double getArea() {
return radius * radius * Math.PI;
}
}
package dishisanzhang;
public class ComparableCircle extends Circle implements Comparable< ComparableCircle > {
public ComparableCircle() {
super();
}
public ComparableCircle(double radius) {
super(radius);
}
@Override
public int compareTo(ComparableCircle o) {
if (this.getArea() > o.getArea()) {
return 1;
} else if (this.getArea() < o.getArea()) {
return -1;
} else
return 0;
}
}
package dishisanzhang;
public class dishisanzhang {
public static void main(String[] args) {
// TODO Auto-generated method stub
ComparableCircle c1 = new ComparableCircle(2.0);
ComparableCircle c2 = new ComparableCircle(3.0);
if (c1.compareTo(c2) > 0)
System.out.println(“c1 > c2”);
else if (c1.compareTo(c2) == 0)
System.out.println(“c1 = c2”);
else
System.out.println(“c1 < c2”);
}
}
=================================================================
package dishisanzhang;
import java.util.Date;
public abstract class GeometricObject {
private String color;
private boolean filled;
private Date dateCreated;
protected GeometricObject(){
dateCreated = new Date();
}
protected GeometricObject(String color,boolean filled){
this.color = color;
this.filled = filled;
dateCreated = new Date();
}
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;
}
@Override
public String toString(){
return "Created on “+dateCreated+”\nColor: “+color+”\nFilled: "+filled;
}
public abstract double getArea();
public abstract double getPerimeter();
}
package dishisanzhang;
interface Colorable {
public abstract void howToColor();
}
package dishisanzhang;
public class Square extends GeometricObject implements Colorable{
private double width;
private double height;
public Square(){
}
public Square(double width,double height){
this(width,height,“white”,false);
}
public Square(double width, double height, String color, boolean filled) {
super(color, filled);
this.width = width;
this.height = height;
}
@Override
public double getArea() {
return width * height;
}
@Override
public double getPerimeter() {
return 2 * (width + height);
}
@Override
public void howToColor(){
System.out.println(“Color all four sides”);
}
@Override
public String toString(){
if(super.isFilled())
howToColor();
return super.toString();
}
}
package dishisanzhang;
最后
看完上述知识点如果你深感Java基础不够扎实,或者刷题刷的不够、知识不全面
小编专门为你量身定制了一套<Java一线大厂高岗面试题解析合集:JAVA基础-中级-高级面试+SSM框架+分布式+性能调优+微服务+并发编程+网络+设计模式+数据结构与算法>
针对知识面不够,也莫慌!还有一整套的<Java核心进阶手册>,可以瞬间查漏补缺
全都是一丢一丢的收集整理纯手打出来的
更有纯手绘的各大知识体系大纲,可供梳理:Java筑基、MySQL、Redis、并发编程、Spring、分布式高性能架构知识、微服务架构知识、开源框架知识点等等的xmind手绘图~
《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》,点击传送门,即可获取!
- (width + height);
}
@Override
public void howToColor(){
System.out.println(“Color all four sides”);
}
@Override
public String toString(){
if(super.isFilled())
howToColor();
return super.toString();
}
}
package dishisanzhang;
最后
看完上述知识点如果你深感Java基础不够扎实,或者刷题刷的不够、知识不全面
小编专门为你量身定制了一套<Java一线大厂高岗面试题解析合集:JAVA基础-中级-高级面试+SSM框架+分布式+性能调优+微服务+并发编程+网络+设计模式+数据结构与算法>
[外链图片转存中…(img-GqJlXIXS-1714693336410)]
针对知识面不够,也莫慌!还有一整套的<Java核心进阶手册>,可以瞬间查漏补缺
[外链图片转存中…(img-w8wDEnp3-1714693336411)]
全都是一丢一丢的收集整理纯手打出来的
更有纯手绘的各大知识体系大纲,可供梳理:Java筑基、MySQL、Redis、并发编程、Spring、分布式高性能架构知识、微服务架构知识、开源框架知识点等等的xmind手绘图~
[外链图片转存中…(img-NdOz0xan-1714693336411)]
[外链图片转存中…(img-veZGlky1-1714693336411)]
《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》,点击传送门,即可获取!