Mit der Grundlage von OO begann ich das Designmodell sorgfältig zu studieren! Entwurfsmuster sind für Java -Design unerlässlich!
Apple.java
Paketstrategie;/** * * @Author Andy * */public class Apple implementiert reduzierbar {// Gewicht privates Doppelgewicht; // Der tatsächliche Einheitspreis ist entworfen und Geld und andere genaue Berechnungen sind bigdecimal; privater Doppelpreis; // diskontiert durch Kaufmenge // privater Discountor d = neuer AppleWeigescountor (); // diskontiert durch Kauf Gesamtpreis privater Discountor D = neuer Applepricediscountor (); public double getWeight () {Return Gewicht; } public void setWeight (doppeltes Gewicht) {this.weight = Gewicht; } public double getPrice () {Rückgabepreis; } public void setPrice (Doppelpreis) {this.price = price; } public Apple (Doppelgewicht, Doppelpreis) {Super (); this.gewicht = Gewicht; this.price = Preis; } @Override public void Discount () {d.discount (this); }}Banana.java
Paketstrategie;/** * * @Author Andy * * */Public Class Banana implementiert diskontable {// Gewicht privates Doppelgewicht; ///// Die tatsächliche Preisentwicklung der Einheit beinhaltet genaue Berechnungen wie Geld und andere Dinge. Öffentliche Banane (Doppelgewicht, Doppelpreis) {Super (); this.gewicht = Gewicht; this.price = Preis; } public double getWeight () {Rückgabegewicht; } public void setWeight (doppeltes Gewicht) {this.weight = Gewicht; } public double getPrice () {Rückgabepreis; } public void setPrice (Doppelpreis) {this.price = price; } @Override public void DiscountSell () {// Rabattalgorithmus if (Gewicht <5) {System.out.println ("Banana undcounted Price:" + Gewicht * Preis); } else if (Gewicht> = 5 && Gewicht <10) {System.out.println ("Banane hat 80% ermäßigten Preis:" + Gewicht * Preis * 0,88); } else if (Gewicht> = 10) {System.out.println ("Banana 50% Rabattpreis:" + Gewicht * Preis * 0,5); }}}Markt.java
Paketstrategie;/** * * @Author Andy * */public class Market {/** * Rabatte für reduzierte Artikel * @param Apple */public static void RabattReduzierbar.java
Paketstrategie;/** * * @Author Andy * */public interface DRONDABE {public void recountSell ();}Test.java
Paketstrategie;/** * * @Author Andy * */public class Test {/** * * @param args */public static void main (String [] args) {// Sie können Apple nur reduzieren, aber nicht allgemeine Dinge, und Sie schreiben einen Rabattalgorithmus, wenn Sie verkaufen // Tatsächlich (10-Apfeln). Ermäßigbare D1 = neue Banane (5,4, 1,1); Markt.discountsell (d); Markt.discountsell (D1); }}