Now that we have a bit more details compared to your initial question, here's how I'll roughly separate the code...
1. Reading from file (input)
In your example, you have a long String
declared as factories
, which is comma-delimited. Does that imply your input is from a CSV file? If so, you should read up on external third-party libraries that can read a line from a CSV file correctly (i.e. taking into consideration escaped commas, quotes, maybe even do some light data type conversion) and return you a meaningful representation, such as a List
of String
fields. Afterwards, you can extract the discrete field values to construct your Company
objects.
2. Summing up values (processing)
Similar to my answer answer to your original question, you do not need two for
loops to traverse and selectively update values in your map
. It is easier to simply think of this step as nothing more than a summation of the map
's values categorized by the brands, as recorded in your Company
objects.
3. Filtering the output (output)
This is where you perform the filtering on the map
's entries to selectively display the brands with ____ (price?) greater than your specified value of 10000
.
Putting it together
An example class structure can be as such:
public class CarReport {
private static List<String> readFile(final String fileName) {
// use a CSV library to parse the file
return rows;
}
private static List<Company> parseData(final List<String> rows) {
// convert "car,price" into a new Company(car, price)
return companyList;
}
private static Map<String, BigDecimal> sumPricesByBrand(final List<Company> companyList) {
// loop through companyList and incrementally add the prices to the map
return map;
}
private static void displayFilteredOutput(final Map<String, BigDecimal> map, final BigDecimal threshold) {
for (Entry<String, BigDecimal> entry : map.entrySet()) {
// if entry.getValue() is more than threshold, display it
}
}
public static void main(String[] args) {
// example
displayFilteredOutput(sumPricesByBrand(parseData(readFile("/path/to/input.csv"))), new BigDecimal("10000"));
}
}
Now that we have a bit more details compared to your initial question, here's how I'll roughly separate the code...
1. Reading from file (input)
In your example, you have a long String
declared as factories
, which is comma-delimited. Does that imply your input is from a CSV file? If so, you should read up on external third-party libraries that can read a line from a CSV file correctly (i.e. taking into consideration escaped commas, quotes, maybe even do some light data type conversion) and return you a meaningful representation, such as a List
of String
fields. Afterwards, you can extract the discrete field values to construct your Company
objects.
2. Summing up values (processing)
Similar to my answer to your original question, you do not need two for
loops to traverse and selectively update values in your map
. It is easier to simply think of this step as nothing more than a summation of the map
's values categorized by the brands, as recorded in your Company
objects.
3. Filtering the output (output)
This is where you perform the filtering on the map
's entries to selectively display the brands with ____ (price?) greater than your specified value of 10000
.
Putting it together
An example class structure can be as such:
public class CarReport {
private static List<String> readFile(final String fileName) {
// use a CSV library to parse the file
return rows;
}
private static List<Company> parseData(final List<String> rows) {
// convert "car,price" into a new Company(car, price)
return companyList;
}
private static Map<String, BigDecimal> sumPricesByBrand(final List<Company> companyList) {
// loop through companyList and incrementally add the prices to the map
return map;
}
private static void displayFilteredOutput(final Map<String, BigDecimal> map, final BigDecimal threshold) {
for (Entry<String, BigDecimal> entry : map.entrySet()) {
// if entry.getValue() is more than threshold, display it
}
}
public static void main(String[] args) {
// example
displayFilteredOutput(sumPricesByBrand(parseData(readFile("/path/to/input.csv"))), new BigDecimal("10000"));
}
}
Now that we have a bit more details compared to your initial question, here's how I'll roughly separate the code...
1. Reading from file (input)
In your example, you have a long String
declared as factories
, which is comma-delimited. Does that imply your input is from a CSV file? If so, you should read up on external third-party libraries that can read a line from a CSV file correctly (i.e. taking into consideration escaped commas, quotes, maybe even do some light data type conversion) and return you a meaningful representation, such as a List
of String
fields. Afterwards, you can extract the discrete field values to construct your Company
objects.
2. Summing up values (processing)
Similar to my answer to your original question, you do not need two for
loops to traverse and selectively update values in your map
. It is easier to simply think of this step as nothing more than a summation of the map
's values categorized by the brands, as recorded in your Company
objects.
3. Filtering the output (output)
This is where you perform the filtering on the map
's entries to selectively display the brands with ____ (price?) greater than your specified value of 10000
.
Putting it together
An example class structure can be as such:
public class CarReport {
private static List<String> readFile(final String fileName) {
// use a CSV library to parse the file
return rows;
}
private static List<Company> parseData(final List<String> rows) {
// convert "car,price" into a new Company(car, price)
return companyList;
}
private static Map<String, BigDecimal> sumPricesByBrand(final List<Company> companyList) {
// loop through companyList and incrementally add the prices to the map
return map;
}
private static void displayFilteredOutput(final Map<String, BigDecimal> map, final BigDecimal threshold) {
for (Entry<String, BigDecimal> entry : map.entrySet()) {
// if entry.getValue() is more than threshold, display it
}
}
public static void main(String[] args) {
// example
displayFilteredOutput(sumPricesByBrand(parseData(readFile("/path/to/input.csv"))), new BigDecimal("10000"));
}
}
Now that we have a bit more details compared to your initial question, here's how I'll roughly separate the code...
1. Reading from file (input)
In your example, you have a long String
declared as factories
, which is comma-delimited. Does that imply your input is from a CSV file? If so, you should read up on external third-party libraries that can read a line from a CSV file correctly (i.e. taking into consideration escaped commas, quotes, maybe even do some light data type conversion) and return you a meaningful representation, such as a List
of String
fields. Afterwards, you can extract the discrete field values to construct your Company
objects.
2. Summing up values (processing)
Similar to my answer to your original question, you do not need two for
loops to traverse and selectively update values in your map
. It is easier to simply think of this step as nothing more than a summation of the map
's values categorized by the brands, as recorded in your Company
objects.
3. Filtering the output (output)
This is where you perform the filtering on the map
's entries to selectively display the brands with ____ (price?) greater than your specified value of 10000
.
Putting it together
An example class structure can be as such:
public class CarReport {
private static List<String> readFile(final String fileName) {
// use a CSV library to parse the file
return rows;
}
private static List<Company> parseData(final List<String> rows) {
// convert "car,price" into a new Company(car, price)
return companyList;
}
private static Map<String, BigDecimal> sumPricesByBrand(final List<Company> companyList) {
// loop through companyList and incrementally add the prices to the map
return map;
}
private static void displayFilteredOutput(final Map<String, BigDecimal> map, final BigDecimal threshold) {
for (Entry<String, BigDecimal> entry : map.entrySet()) {
// if entry.getValue() is more than threshold, display it
}
}
public static void main(String[] args) {
// example
displayFilteredOutput(sumPricesByBrand(parseData(readFile("/path/to/input.csv"))), new BigDecimal("10000"));
}
}
Now that we have a bit more details compared to your initial question, here's how I'll roughly separate the code...
1. Reading from file (input)
In your example, you have a long String
declared as factories
, which is comma-delimited. Does that imply your input is from a CSV file? If so, you should read up on external third-party libraries that can read a line from a CSV file correctly (i.e. taking into consideration escaped commas, quotes, maybe even do some light data type conversion) and return you a meaningful representation, such as a List
of String
fields. Afterwards, you can extract the discrete field values to construct your Company
objects.
2. Summing up values (processing)
Similar to my answer to your original question, you do not need two for
loops to traverse and selectively update values in your map
. It is easier to simply think of this step as nothing more than a summation of the map
's values categorized by the brands, as recorded in your Company
objects.
3. Filtering the output (output)
This is where you perform the filtering on the map
's entries to selectively display the brands with ____ (price?) greater than your specified value of 10000
.
Putting it together
An example class structure can be as such:
public class CarReport {
private List<String> readFile(final String fileName) {
// use a CSV library to parse the file
return rows;
}
private List<Company> parseData(final List<String> rows) {
// convert "car,price" into a new Company(car, price)
return companyList;
}
private Map<String, BigDecimal> sumPricesByBrand(final List<Company> companyList) {
// loop through companyList and incrementally add the prices to the map
return map;
}
private void displayFilteredOutput(final Map<String, BigDecimal> map, final BigDecimal threshold) {
for (Entry<String, BigDecimal> entry : map.entrySet()) {
// if entry.getValue() is more than threshold, display it
}
}
public static void main(String[] args) {
// example
displayFilteredOutput(sumPricesByBrand(parseData(readFile("/path/to/input.csv"))), new BigDecimal("10000"));
}
}
Now that we have a bit more details compared to your initial question, here's how I'll roughly separate the code...
1. Reading from file (input)
In your example, you have a long String
declared as factories
, which is comma-delimited. Does that imply your input is from a CSV file? If so, you should read up on external third-party libraries that can read a line from a CSV file correctly (i.e. taking into consideration escaped commas, quotes, maybe even do some light data type conversion) and return you a meaningful representation, such as a List
of String
fields. Afterwards, you can extract the discrete field values to construct your Company
objects.
2. Summing up values (processing)
Similar to my answer to your original question, you do not need two for
loops to traverse and selectively update values in your map
. It is easier to simply think of this step as nothing more than a summation of the map
's values categorized by the brands, as recorded in your Company
objects.
3. Filtering the output (output)
This is where you perform the filtering on the map
's entries to selectively display the brands with ____ (price?) greater than your specified value of 10000
.
Putting it together
An example class structure can be as such:
public class CarReport {
private static List<String> readFile(final String fileName) {
// use a CSV library to parse the file
return rows;
}
private static List<Company> parseData(final List<String> rows) {
// convert "car,price" into a new Company(car, price)
return companyList;
}
private static Map<String, BigDecimal> sumPricesByBrand(final List<Company> companyList) {
// loop through companyList and incrementally add the prices to the map
return map;
}
private static void displayFilteredOutput(final Map<String, BigDecimal> map, final BigDecimal threshold) {
for (Entry<String, BigDecimal> entry : map.entrySet()) {
// if entry.getValue() is more than threshold, display it
}
}
public static void main(String[] args) {
// example
displayFilteredOutput(sumPricesByBrand(parseData(readFile("/path/to/input.csv"))), new BigDecimal("10000"));
}
}
Now that we have a bit more details compared to your initial question, here's how I'll roughly separate the code...
1. Reading from file (input)
In your example, you have a long String
declared as factories
, which is comma-delimited. Does that imply your input is from a CSV file? If so, you should read up on external third-party libraries that can read a line from a CSV file correctly (i.e. taking into consideration escaped commas, quotes, maybe even do some light data type conversion) and return you a meaningful representation, such as a List
of String
fields. Afterwards, you can extract the discrete field values to construct your Company
objects.
2. Summing up values (processing)
Similar to my answer to your original question, you do not need two for
loops to traverse and selectively update values in your map
. It is easier to simply think of this step as nothing more than a summation of the map
's values categorized by the brands, as recorded in your Company
objects.
3. Filtering the output (output)
This is where you perform the filtering on the map
's entries to selectively display the brands with ____ (price?) greater than your specified value of 10000
.
Summing all upPutting it together
A recommendedAn example class structure can be as such:
public class CarReport {
private List<String> readFile(final String fileName) {
// use a CSV library to parse the file
return rows;
}
private List<Company> parseData(final List<String> rows) {
// convert "car,price" into a new Company(car, price)
return companyList;
}
private Map<String, BigDecimal> sumPricesByBrand(final List<Company> companyList) {
// loop through companyList and incrementally add the prices to the map
return map;
}
private void displayFilteredOutput(final Map<String, BigDecimal> map, final BigDecimal threshold) {
for (Entry<String, BigDecimal> entry : map.entrySet()) {
// if entry.getValue() is more than threshold, display it
}
}
public static void main(String[] args) {
// example
displayFilteredOutput(sumPricesByBrand(parseData(readFile("/path/to/input.csv"))), new BigDecimal("10000"));
}
}
Now that we have a bit more details compared to your initial question, here's how I'll roughly separate the code...
1. Reading from file (input)
In your example, you have a long String
declared as factories
, which is comma-delimited. Does that imply your input is from a CSV file? If so, you should read up on external third-party libraries that can read a line from a CSV file correctly (i.e. taking into consideration escaped commas, quotes, maybe even do some light data type conversion) and return you a meaningful representation, such as a List
of String
fields. Afterwards, you can extract the discrete field values to construct your Company
objects.
2. Summing up values (processing)
Similar to my answer to your original question, you do not need two for
loops to traverse and selectively update values in your map
. It is easier to simply think of this step as nothing more than a summation of the map
's values categorized by the brands, as recorded in your Company
objects.
3. Filtering the output (output)
This is where you perform the filtering on the map
's entries to selectively display the brands with ____ (price?) greater than your specified value of 10000
.
Summing all up
A recommended class structure can be as such:
public class CarReport {
private List<String> readFile(final String fileName) {
// use a CSV library to parse the file
return rows;
}
private List<Company> parseData(final List<String> rows) {
// convert "car,price" into a new Company(car, price)
return companyList;
}
private Map<String, BigDecimal> sumPricesByBrand(final List<Company> companyList) {
// loop through companyList and incrementally add the prices to the map
return map;
}
private void displayFilteredOutput(final Map<String, BigDecimal> map, final BigDecimal threshold) {
for (Entry<String, BigDecimal> entry : map.entrySet()) {
// if entry.getValue() is more than threshold, display it
}
}
public static void main(String[] args) {
// example
displayFilteredOutput(sumPricesByBrand(parseData(readFile("/path/to/input.csv"))), new BigDecimal("10000"));
}
}
Now that we have a bit more details compared to your initial question, here's how I'll roughly separate the code...
1. Reading from file (input)
In your example, you have a long String
declared as factories
, which is comma-delimited. Does that imply your input is from a CSV file? If so, you should read up on external third-party libraries that can read a line from a CSV file correctly (i.e. taking into consideration escaped commas, quotes, maybe even do some light data type conversion) and return you a meaningful representation, such as a List
of String
fields. Afterwards, you can extract the discrete field values to construct your Company
objects.
2. Summing up values (processing)
Similar to my answer to your original question, you do not need two for
loops to traverse and selectively update values in your map
. It is easier to simply think of this step as nothing more than a summation of the map
's values categorized by the brands, as recorded in your Company
objects.
3. Filtering the output (output)
This is where you perform the filtering on the map
's entries to selectively display the brands with ____ (price?) greater than your specified value of 10000
.
Putting it together
An example class structure can be as such:
public class CarReport {
private List<String> readFile(final String fileName) {
// use a CSV library to parse the file
return rows;
}
private List<Company> parseData(final List<String> rows) {
// convert "car,price" into a new Company(car, price)
return companyList;
}
private Map<String, BigDecimal> sumPricesByBrand(final List<Company> companyList) {
// loop through companyList and incrementally add the prices to the map
return map;
}
private void displayFilteredOutput(final Map<String, BigDecimal> map, final BigDecimal threshold) {
for (Entry<String, BigDecimal> entry : map.entrySet()) {
// if entry.getValue() is more than threshold, display it
}
}
public static void main(String[] args) {
// example
displayFilteredOutput(sumPricesByBrand(parseData(readFile("/path/to/input.csv"))), new BigDecimal("10000"));
}
}