Search Blog

Miyerkules, Pebrero 6, 2013

Write an application that inputs temperature in Celsius and prints out the temperature in Fahrenheit. The formula to convert Celsius to the equivalent Fahrenheit is ------> Fahrenheit = 1.8 x Celsius + 32

Java Codes
--+o0O0o+--


import java.util.Scanner;

public class MachineProblemB1 {

    public static void main(String[] args) {

        Scanner input_user = new Scanner(System.in);
       
        double Celsius,Fahrenheit;
              System.out.println("==========================================");
System.out.println("||  Celsius to Fahrenheit Converter     ||");        System.out.println("==========================================");
       
        System.out.print(" Enter temperature in Celsius:      ");
        Celsius = input_user.nextDouble();
       
        Fahrenheit = 1.8 * Celsius + 32;
       
        System.out.println("*****************************************");
System.out.println("  Fahrenheit : " + Fahrenheit);
System.out.println("*****************************************");
    }
}

Biyernes, Enero 18, 2013

Write a program that demonstrates the difference between predecrementing and postdecrementing using the decrement operator --.

Java Codes
--+o0O0o+--

Write a program that demonstrates the difference between predecrementing and postdecrementing using the decrement operator --. 


Code:



import java.util.Scanner;

public class MachineProblem12 {

    public static void main(String[] args) {
       
        Scanner input_user = new Scanner(System.in);
       
        int base_num,loop_num,base_num1,x,y;
       
        System.out.println("*****************************************");
       
            System.out.print("  Enter base number: ");
            base_num = input_user.nextInt();
           
            base_num1 = base_num;
           
            System.out.print("  Enter number of loop: ");
            loop_num = input_user.nextInt();
           
            x = 0;
            y = 0;
           
            for(int z = 0;z < loop_num;z++)
            {
                if(z == 0)
                {  
                    x = --base_num;
                    y = base_num1--;
                    System.out.println("");
System.out.println(" xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
System.out.println(" ||# of LOOP||Predecrement||Postdecrement  ||");
System.out.println(" xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
System.out.println(" ||   1st   ||     " + x + "         " + y );
                    System.out.println(" xxxxxxxxxxxxxxx");
                }
                if(z == 1)
                {  
                    x = --base_num;
                    y = base_num1--; 
System.out.println(" ||   2nd   ||     " + x + "         " + y);
                    System.out.println(" xxxxxxxxxxxxxxx");
                }
              


 if(z == 2)
                {  
                    x = --base_num;
                    y = base_num1--;
System.out.println(" ||    3rd    ||      " + x + "      " + y);
                    System.out.println(" xxxxxxxxxxxxxxx");
                }
                if(z > 2)
                {  
                    x = --base_num;
                    y = base_num1--;
System.out.println(" || " + (z + 1) +"th|| " + x + "    " + y);
                    System.out.println(" xxxxxxxxxxxxxxx");
                }
            }
    }
}

Develop a program that will determine the gross pay for each of several employees. The company pays “straight-time” for the first 40 hours worked by each employee and pays “time-and-a-half” for all hours worked in excess of 40 hours. You are given a list of the employees of the company, the number of hours each employee worked last week and the hourly rate of each employee. Your program should input this information for each employee, and should determine and display the employee’s gross pay.


Java Codes
--+o0O0o+--

Develop a program that will determine the gross pay for each of several employees. The company pays “straight-time” for the first 40 hours worked by each employee and pays “time-and-a-half” for all hours worked in excess of 40 hours. You are given a list of the employees of the company, the number of hours each employee worked last week and the hourly rate of each employee. Your program should input this information for each employee, and should determine and display the employee’s gross pay.


Code:


import java.util.Scanner;

public class MachineProblem11 {

    public static void main(String[] args) {

        Scanner input_user = new Scanner(System.in);
       
        float hour_rate,salary;
        int hours_worked;
       
        System.out.println("*****************************************");
        for(int x = 0;x < 1000;x++)
        { 
           
     System.out.print("  Enter # of hours worked (-1 to end): ");
            hours_worked = input_user.nextInt();
           
            if(hours_worked != -1)
            {
System.out.print("  Enter hourly rate of the worker ($00.00): ");
                hour_rate = input_user.nextFloat();
               
                salary = hours_worked * hour_rate;
                System.out.println("*****************************************");
  System.out.println("  The interest charge is $" + salary);
                System.out.println("*****************************************");
            }
            else
            {
                return;
            }        
            
        }
    }
}

The simple interest on a loan is calculated by the formula. interest = principal * rate * days / 365; The preceding formula assumes that rate is the annual interest rate, and therefore includes the division by 365 (days). Develop a program that will input principal, rate and days for several loans, and will calculate and display the simple interest for each loan, using the preceding formula.


Java Codes
--+o0O0o+--

The simple interest on a loan is calculated by the formula.

interest = principal * rate * days / 365;

The preceding formula assumes that rate is the annual interest rate, and therefore includes the division by 365 (days). Develop a program that will input principal, rate and days for several loans, and will calculate and display the simple interest for each loan, using the preceding formula.


Code:


import java.util.Scanner;

public class MachineProblem10 {

    public static void main(String[] args) {
       
        Scanner input_user = new Scanner(System.in);
       
        float principal,rate,interest;
        int loan_days;
       
        System.out.println("*****************************************");
        for(int x = 0;x < 1000;x++)
        { 
           
        System.out.print("  Enter loan principal (-1 to end): ");
            principal = input_user.nextFloat();
           
            if(principal != -1)
            {
                System.out.print("  Enter interest rate: ");
                rate = input_user.nextFloat();
               
          System.out.print("  Enter term of the loan in days: ");
                loan_days = input_user.nextInt();
               
                interest = principal * rate * loan_days / 365;
                System.out.println("*****************************************");
System.out.println("  The interest charge is $" + interest);               System.out.println("*****************************************");
            }
            else
            {
                return;
            }        
            
        }
    }
}

One large chemical company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9% of their gross sales for that week. For example, a salesperson who sells $5000 worth of chemicals in a week receives $200 plus 9% of $5000, or a total of $650. Develop a program that will input each salesperson’s gross sales for last week and will calculate and display that salesperson’s earnings. Process one salesperson’s figures at a time.


Java Codes
--+o0O0o+--

One large chemical company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9% of their gross sales for that week. For example, a salesperson who sells $5000 worth of chemicals in a week receives $200 plus 9% of $5000, or a total of $650. Develop a program that will input each salesperson’s gross sales for last week and will calculate and display that salesperson’s earnings. Process one salesperson’s figures at a time.


Code:


import java.util.Scanner;

public class MachineProblem9 {

    public static void main(String[] args) {
       
        Scanner input_user = new Scanner(System.in);
       
        float salary_$;
        double recieve_this_week;
       
        System.out.println("******************************************");
        for(int x = 0;x < 1000;x++)
        { 
           
     System.out.print("  Enter sales in dollars (-1 to end): ");
            salary_$ = input_user.nextFloat();
           
            if(salary_$ != -1)
            {
                recieve_this_week = 0.09 * salary_$ + 200;
     System.out.println("  Salary is : $" + recieve_this_week);
                System.out.println("*****************************************");
            }
            else
            {
                return;
            }  
               
            
        }
    }
}

Develop a program that will determine if a department store customer has exceeded the credit limit on a charge account. For each customer, the following facts are available: 1. Account number 2. Balance at the beginning of the month 3. Total of all items charged by this customer this month 4. Total of all credits applied to this customer’s account this month 5. Allowed credit limit The program should input each of these facts, calculate the new balance (= beginning balance + charges – credits), and determine if the new balance exceeds the customer’s credit limit. For those customers whose credit limit is exceeded, the program should display the customer’s account number, credit limit, new balance, and the message “Credit limit exceeded.”


Java Codes
--+o0O0o+--


Develop a program that will determine if a department store customer has exceeded the credit limit on a charge account. For each customer, the following facts are available:
1.Account number
2.Balance at the beginning of the month
3.Total of all items charged by this customer this month
4.Total of all credits applied to this customer’s account this month
5.Allowed credit limit

The program should input each of these facts, calculate the new balance (= beginning balance + charges – credits), and determine if the new balance exceeds the customer’s credit limit. For those customers whose credit limit is exceeded, the program should display the customer’s account number, credit limit, new balance, and the message “Credit limit exceeded.”


Code:

import java.util.Scanner;

public class MachineProblem8 {

    public static void main(String[] args) {
       
         Scanner input_user = new Scanner(System.in);
       
        int  account_number;
        float beginning_balance,total_charges;
        float total_credits,credit_limit,new_bal;
       
        System.out.println("*****************************************");
        for(int x = 0;x < 1000;x++)
        { 
           
         System.out.print(" Enter account number (-1 to end): ");
            account_number = input_user.nextInt();
           
            if(account_number != -1)
            {
                System.out.print(" Enter beginning balance: ");
                beginning_balance = input_user.nextFloat();
               
                System.out.print(" Enter total charges: ");
                total_charges = input_user.nextFloat();
               
                System.out.print(" Enter total credits: ");
                total_credits = input_user.nextFloat();
               
                System.out.print(" Enter credit limit: ");
                credit_limit = input_user.nextFloat();


new_bal = beginning_balance + total_charges - total_credits;
                    if(new_bal > credit_limit)
                    {
                        System.out.println("*****************************************");

       System.out.println("     Account: " + account_number);
       System.out.println("     Credit Limit: " + credit_limit);
       System.out.println("     Balance: " + beginning_balance);
                        System.out.println("******************************************");
                        System.out.println("=========================================");
       System.out.println("||     CREDIT LIMIT EXCEEDED    ||");
System.out.println("=========================================");
                    }
               
System.out.println("*****************************************");
            }
            else
            {
                return;
            }  
               
            
        }
    }
}

Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankfuls of gasoline by recording miles driven and gallons used for each tankful. Develop a program that will input the miles driven and gallons used for each tankful. The program should calculate and display the miles per gallon obtained for each tankful. After processing all input information, the program should calculate and print the combined miles per gallon obtained for all tankfuls.


Java Codes

--+o0O0o+--

Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankfuls of gasoline by recording miles driven and gallons used for each tankful. Develop a program that will input the miles driven and gallons used for each tankful. The program should calculate and display the miles per gallon obtained for each tankful. After processing all input information, the program should calculate and print the combined miles per gallon obtained for all tankfuls.


Code:


import java.util.Scanner;

public class MachineProblem7 {

    public static void main(String[] args) {
       
        Scanner input_user = new Scanner(System.in);
       
        float gallons,miles;
        float computed,overall = 0,result = 0,p = 0;
       
        System.out.println("*****************************************");
    
 for(int x = 0;x < 1000;x++)
      { 
           
       System.out.print(" Enter the galloon used (-1 to end): ");
            gallons = input_user.nextFloat();
           
            if(gallons != -1)
            {
                System.out.print(" Enter the miles driven: ");
                miles = input_user.nextFloat();
               
                computed = miles / gallons;
                overall = overall + computed;

System.out.println("The miles / gallon for this tank was " + computed);
                p++;
                System.out.println("*****************************************");
            }
            if(gallons == -1)
            {
                result = overall / p;
                System.out.println("*****************************************");

System.out.println("   The overall average miles / gallon was " + result);
                System.out.println("*****************************************");
                return;
            }        
            
        }
    }
}