kaysar07cuet
BAN USERpublic class ShowPattern {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String input = in.nextLine();
TreeMap<Character, Integer> inputMap = new TreeMap<Character, Integer>();
Integer value;
for (int i = 0; i < input.length(); i++) {
value = inputMap.get(input.charAt(i));
if (value == null) {
value = 1;
}
inputMap.put(input.charAt(i), value + 1);
}
StringBuilder sb = new StringBuilder();
for (Map.Entry<Character, Integer> entry : inputMap.entrySet()) {
value = entry.getValue();
Character key = entry.getKey();
for (int i = 1; i < value; i++) {
sb.append(key);
}
}
System.out.println(sb);
}
}
import java.util.ArrayList;
public class VendingMachine {
private ArrayList<Item> itemlList;
private ArrayList<Item> selectedItems;
private Coin receivedCoin;
public VendingMachine(ArrayList<Item> itemlList) {
this.itemlList = itemlList;
}
public ArrayList<Item> getItemlList() {
return itemlList;
}
public ArrayList<Item> giveCoins(Coin coin){
this.receivedCoin = coin;
return showUserChoiceList();
}
private ArrayList<Item> showUserChoiceList() {
ArrayList<Item> userChoiceList = new ArrayList<Item>();
for(Item item: itemlList){
if(item.getPrice()<=receivedCoin.getValue()){
userChoiceList.add(item);
}
}
return userChoiceList;
}
public Coin getSelectedItem(ArrayList<Item> selectedItems){
this.selectedItems = selectedItems;
return giveSelectedItem();
}
private Coin giveSelectedItem() {
Coin returnCoin=null;
double value = receivedCoin.getValue();
for(Item item: selectedItems){
System.out.println(item.getName()+" | "+item.getPrice());
value=value-item.getPrice();
}
return new Coin(value, receivedCoin.getCurrency());
}
}
- kaysar07cuet January 25, 2014