Beruflich Dokumente
Kultur Dokumente
Exercise 01
public class SumOfTwoNumbers
{
public static void main(String[] args)
{
int number1, number2, total; // Variables
Exercise 02
public class SalesPrediction
{
public static void main(String[] args)
{
double totalSales = 4600000.0; // Total sales
double amparaSales; // Ampara district sales
Exercise 03
public class NameAgeAnnualIncome
{
public static void main(String[] args)
{
String name; // To hold a name
int age; // To hold an age
double annualIncome; // To hold annualIncome
// Display a message.
System.out.println("My name is " + name + ", my age is " + age +
" and I hope to earn Rs." +annualIncome+ " per year.");
}
}
Exercise 06 (Constants)
public class StockCommission
{
public static void main(String[] args)
{
// Constants
final int NUM_SHARES = 600; // Number of shares
final double STOCK_PRICE = 21.77; // Price per share
final double COMM_PERCENT = 0.02; // Commission percentage
// Variables
double stockCost; // Cost of stock
double commission; // Commission
double total; // Total of the transaction
Exercise 07
public class EnergyDrinks
{
public static void main(String[] args)
{
// Constant for the number surveyed
final int NUM_SURVEYED = 12467;
// Variables
double energyDrinkers; // Number of energy drinkers
double preferCitrus; // Number that prefer citrus
Exercise 08
import java.util.Scanner; // Needed for the Scanner class
Exercise 09
import java.util.Scanner;
// Variables
double mealCharge; // To hold the meal charge
double tax; // To hold the amount of tax
double tip; // To hold the tip amount
double total; // To hold the total charge
// Variables
double purchase; // Amount of purchase
double stateTax; // Amount of state sales tax
double countyTax; // Amount of county sales tax
double totalTax; // Total sales tax
double totalCost; // Total cost of the purchase
// Calculate the total amount SaNa paid for the stock plus the
// broker's commission and store the result in amountPaid.
double amountPaid = stockPurchase + purchaseComm;
// Calculate the amount SaNa sold the stock for and store
// the result in stockSale.
double stockSale = NUM_SHARES * SELLING_PRICE;
Exercise 13
import java.util.Scanner; // Needed for the Scanner class
public class StringManipulator
{
public static void main(String[] args)
{
String city; // To hold user input
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the name of your favorite city: ");
city = keyboard.nextLine();