package com.robertolab.training;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
public class Article {
private float marketPrice;
private float margin;
public Article
(String name,
float marketPrice,
float margin
) {
this.name = name;
this.marketPrice = marketPrice;
this.margin = margin;
}
return name;
}
public void setName
(String name
) {
this.name = name;
}
public float getMarketPrice() {
return marketPrice;
}
public void setMarketPrice(float marketPrice) {
this.marketPrice = marketPrice;
}
public float getMargin() {
return margin;
}
public void setMargin(float margin) {
this.margin = margin;
}
@Override
return "("+name
+", " + String.
format(Locale.
ROOT,
"%.0f", marketPrice
)+ ", " + String.
format(Locale.
ROOT,
"%.2f", margin
) + "%)";
}
public static void main
(String[] args
) {
List<Article> articles = new ArrayList<Article>();
articles.add(new Article("Shower Gel",3f, 60.00f));
articles.add(new Article("Board game",20f, 130.00f));
articles.add(new Article("Bicycle", 250f, 80.00f));
articles.add(new Article("Strawberries", 10f, 50.00f));
for(Article art : articles) {
System.
out.
print(art.
toString());
}
float[] discounts = new float[] {0,0.10f,0.15f,0.25f};
float sum = 0.0f;
// for(Article art : articles) {
// sum += art.getMarketPrice()+(art.getMarketPrice()*art.getMargin()/100);
// }
for(int i =0; i < discounts.length; i++) {
for(Article art : articles) {
sum = sum + ((art.getMarketPrice()+(art.getMarketPrice()*art.getMargin()/100))-
(art.getMarketPrice()+(art.getMarketPrice()*art.getMargin()/100))*discounts[i]);
}
//sum = sum -(sum*discounts[i]);
System.
out.
println("Articles’ price after " + discounts
[i
]*100 + "% discount: " + String.
format(Locale.
ROOT,
"%.2f", sum
));
//System.out.println("Articles’ price after " + discounts[i]*100 + "% discount: " + String.format(Locale.ROOT, "%.2f", sum-(sum*discounts[i])));
}
}
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}