Develop a Java program for a car dealership shop that allows the dealer to enter the buying price of 5 cars and their models. the program then computes and displays the selling price and profit of each car the rate for selling price is 240% of buying price. Selling price = buying price * rate , profit = selling price - buying price .
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String[] models = new String[5];
double[] prices = new double[models.length];
for (int i = 0; i < models.length; i++) {
System.out.println("Model:");
models[i] = in.nextLine();
System.out.println("Price:");
prices[i] = Double.parseDouble(in.nextLine());
}
for (int i = 0; i < models.length; i++) {
double sellingPrice = prices[i] * 2.4;
System.out.println(models[i] + " Selling price: " + sellingPrice + "; Profit: "
+ (sellingPrice - prices[i]));
}
}
}
Comments
Leave a comment