Ex 6: Sales Prediction

The East Coast Sales division of a company generates 62 percent of the total sales. Based on that percentage, write a program that will predict how much the East Coast division will generate if the company has $4.6 million in sales this year.

Solution:

final double PERCENT = 0.4;

double total_sale = 4.6;

double east_coast_share = PERCENT * total_sale;

System.out.println( “The east end generated $ “ + east_end_share + “ millions this year”);

Ex 7: Land Calculation

One acre of land is equivalent to 43,560 square feet. Write a program that calculates the number of acres in a tract of land with 389,767 square feet.

Explanation:

1 acre à 43560 square feet

n acres à 389767 square feet

n = 389767 / 43560

Solution:

final int ONE_ACRE = 43560;

int acres;

int land_area = 389767;

acres = land_area / ONE_ACRE;

System.out.println( “The number of acres in “ + land_area + “ square feet is “ + acres +

“ acres. “);

Ex 8: Sales Tax:

Write a program that will ask the user to enter the amount of a purchase. The program should then compute the state and county sales tax. Assume that the sale tax is 4 percent and the county sales tax is 2 percent. The program should display the amount of the purchase, the state sales tax, the county sales tax, the total sales tax, and the total of the sale (which is the sum of the amount of purchase plus the total sales tax)

Solution:

double amount_of_purchase;

final double STATE_RATE = 0.04;

final double COUNTY_RATE = 0.02;

double state_tax, county_tax, total_tax, total_sale;

amount_of_purchase = Double.parseDouble ( JOptionPane.showInputDialog(

“Enter the amount of purchases”));

state_tax = amount_of_purchase * STATE_RATE;

county_tax = amount_of_purchase * COUNTY_RATE;

total_tax = state_tax + county_tax;

total_sale= amount_of_purchase + total_tax;

JOptionPane.showMessageDialog( null, “ Amount of purchases: “ + amount_of_purchase + “\n State Tax: “ + state_tax + “\n County Tax: ” + county_tax + “\n Total Tax: “ + total_tax + “\n total: “ + total_sale );

Ex 11: Circuit Board Profit

An electronics company sells circuit boards at a 40 percent profit. If you know the retail price of a circuit board you can calculate its profit with the following formula:

Profit = retail price * 0.4

Write a program that asks the user for the retail price of a circuit board calculates the amount of profit earned for that product and displays the result on the screen.

Solution:

import javax.swing.JOptionPane;

public class CalculateProfit {

public static void main ( String args [] ) {

double profit, retail_price;

final double PERCENTAGE = 0.4;

retail_price = Double.parseDouble( JOptionPane.showInputDialog(

“Enter Retail Price”));

profit = retail_price * PERCENTAGE;

JOptionPane.showMessage( null, “The profit is \n$” + profit);

System.exit(0);

}

}