# Thread: Looks like I知 doing procedural programming

1. Member
Join Date
Mar 2015
Posts
1
Rep Power
0

## Looks like I知 doing procedural programming

Any tips to make it more OOP?
It痴 my first Java program to calculate the total cost of elixir during an attack in the game Clan of Clash.

Java Code:
```import java.io.BufferedReader;

public class ClashOfClan {

private static String[] units = {"Barbarians ", "Archers ", "Giants ", "Goblins ", "Wall Breakers ", "Balloons ", "Wizards ", "Healers ", "Dragons ", "Pekka "};
private static int[] elixirCost = {100, 200, 2250, 100, 3000, 4000, 3500, 8000, 30000, 35000};
static int counter = 0;
static String zero = "0";
static int value = 0;

public static void main(String[] args) {

System.out.println("How many.... ");
finalValue();
System.out.println("Total elixir used: " + value);

}

private static void finalValue() {
for (int i = 0; i < units.length; i++) {
value += totalCost();
}
}

private static int convertInput() {
String unit = checkUnit();
String input = getInput(unit);
if (input.isEmpty()) {
input = zero;
}
int convertInput = Integer.parseInt(input);
return convertInput;

}

private static int totalCost() {
int totalCost = addingCost * elixirCost[counter];
counter++;
}

private static String checkUnit() {
String unit = units[counter];
return unit;
}

private static String getInput(String prompt) {

System.out.print(prompt);
System.out.flush();

try {
} catch (Exception e) {
return "Error: " + e.getMessage();
}
}
}```

2. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
15

## Re: Looks like I知 doing procedural programming

Get rid of your static methods and variables for one. If units and elixarCosts are related, why not combine them in a class? And it seems like some of your methods are gratuitous. For example, you only call checkUnit() and getInput() at one location. So why use methods?

Regards,
Jim

3. Member
Join Date
Feb 2015
Posts
5
Rep Power
0

## Re: Looks like I知 doing procedural programming

Is quite a bare bones class, so not much to do, maybe an Unit class that holds (name, price), as i said not much to look at so yea.

4. ## Re: Looks like I知 doing procedural programming

Originally Posted by luckylucky
Looks like I知 doing procedural programming
Also looks like you're cross posting.

first program in Java, how to make it less procedural and more OOP (Beginning Java forum at JavaRanch)

db

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•