Skip to content

Instantly share code, notes, and snippets.

@cbilson
Last active February 9, 2017 12:40
Show Gist options
  • Save cbilson/24be28b27a9adcb5be75c97e91461d23 to your computer and use it in GitHub Desktop.
Save cbilson/24be28b27a9adcb5be75c97e91461d23 to your computer and use it in GitHub Desktop.
import java.io.File;
import java.io.FileNotFoundException;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Scanner;
public class DroidExpenses {
public static void main(String[] args) throws FileNotFoundException {
//Scanner scanner = new Scanner(System.in);
Scanner scanner = new Scanner(new File("C:\\Users\\cbilson\\DroidExpenses.txt"));
double blastRiflePrice = 350.34;
double visualSensorPrice = 230.90;
double auditorySensorPrice = 190.55;
double armPrice = 125.30;
double legPrice = 180.90;
NumberFormat formatter = new DecimalFormat("#.00");
int problems = scanner.nextInt();
for (int i = 0; i < problems; i++) {
double cost = 0.0;
cost += scanner.nextInt() * blastRiflePrice;
cost += scanner.nextInt() * visualSensorPrice;
cost += scanner.nextInt() * auditorySensorPrice;
cost += scanner.nextInt() * armPrice;
cost += scanner.nextInt() * legPrice;
System.out.println("$" + formatter.format(cost));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment