i've been puzzling over this for about 5 hours now, I just can't get the errors to stop. am I doing something fundamentally wrong, or misunderstanding something? I'm hoping this is fairly simple to some people, as i'm just learning. the point of this program is to calculate taxes and dealership fees on cars using methods and arrays.
package taxesandfeescar;
import java.util.Scanner;
import java.util.Arrays;
/**
*
* @author K
*/
public class Taxesandfeescar {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("How many vehicle prices would you like to store?");
int pricesNumber = input.nextInt();
int Prices[] = new int[pricesNumber];
for(int i = 0; i < pricesNumber; i ) {
int imsg = i 1;
System.out.println("Please enter the price, Without taxes or fees, of car #" imsg);
Prices[i] = input.nextInt();
}
for(int i = 0; i < pricesNumber; i ) {
int imsg = i 1;
System.out.println("The final price, after taxes and fees of car #" imsg " is " pricesTaxFees[i]);
Prices[i] = input.nextInt();
int pricesTaxFees[i] = applyTaxesAndFees[i];
}
}
public static double[] applyTaxesAndFees(int Prices, int pricesNumber){
int pricesTaxFees[pricesNumber];
for(int i = 0; i < pricesNumber; i ) {
pricesTaxFees[i] = Prices[i] / 13 * 100 1500;
}
return pricesTaxFees[];
}
}
CodePudding user response:
You have several errors in your code. For example: you dont have to read twice the price of the car. You cannot print the message with the final price before calculating the final price. When you have defined like that applyTaxesAndFees(int Prices, int pricesNumber) you cannot call it like thatapplyTaxesAndFees[i], it is totaly wrong. You shoul call this method like applyTaxesAndFees(Price, priceNumber).
Anyway, check the code above and find and learn from your mistakes like we all do. Have fun with java.
This will work for you.
import java.util.Scanner;
import java.util.Arrays;
/**
*
* @author K
*/
public class Taxesandfeescar {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("How many vehicle prices would you like to store?");
int pricesNumber = input.nextInt();
int Prices[] = new int[pricesNumber];
int pricesTaxFees[] = new int[pricesNumber];
for(int i = 0; i < pricesNumber; i ) {
int imsg = i 1;
System.out.println("Please enter the price, Without taxes or fees, of car #" imsg);
Prices[i] = input.nextInt();
}
for(int i = 0; i < pricesNumber; i ) {
int imsg = i 1;
pricesTaxFees[i] = applyTaxesAndFees(Prices[i]);
System.out.println("The final price, after taxes and fees of car #" imsg " is " pricesTaxFees[i]);
}
}
public static int applyTaxesAndFees(int Price){
int pricesTaxFees = 0;
pricesTaxFees = Price / 13 * 100 1500;
return pricesTaxFees;
}
}
CodePudding user response:
Here is something working:
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("How many vehicle prices would you like to store?");
int numberOfVehicles = input.nextInt();
double[] vehiclePrices = new double[numberOfVehicles];
for (int i = 0; i < numberOfVehicles; i ) {
int vehicleNumber = i 1;
System.out.println("Please enter the price, Without taxes or fees, of car #" vehicleNumber);
vehiclePrices[i] = input.nextInt();
}
for (int i = 0; i < numberOfVehicles; i ) {
int vehicleNumber = i 1;
vehiclePrices[i] = applyTaxesAndFees(vehiclePrices[i]);
System.out.println("The final price, after taxes and fees of car #" vehicleNumber " is " vehiclePrices[i]);
}
}
public static double applyTaxesAndFees(double pricesBeforeTaxes) {
double priceAfterTaxes = pricesBeforeTaxes ((pricesBeforeTaxes * 13) / 100) 1500;
return priceAfterTaxes;
}
my advice would be to check the changes line by line and see the differences. I'm learning as well, but would recommend you to read more about how methods and arrays works. Also - naming conventions are important.