Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA PROGRAMMING A bank charges a base fee of $10 per month, plus the following

ID: 3670954 • Letter: J

Question

JAVA PROGRAMMING

A bank charges a base fee of $10 per month, plus the following check fees for a commercial checking account:

$.10 each for less than 20 checks

$.08 each for 20-39 checks

$.06 each for 40-59 checks

$.04 each for 60 or more checks.

Write a JAVA program that asks for the number of checks written for the month. The program should then calculate and display the bank's service fees for the month.

B)

Write a JAVA program that asks the user to enter three names, and then displays the names sorted in ascending order. For example, if the user entered in "Charlie", "Leslie", and "Andy", the program would display:

Andy

Charlie

Leslie

Explanation / Answer

import java.io.*;

public class HelloWorld
   {
       double fees,
           checkFee,
           overdraftFee,
           balance;
       int checks;
      
       public HelloWorld()
       {
           balance = 1000.0;
       }
       public void setFees(int checksWritten)
       {
           checks = checksWritten;
          
           if (checks < 20)
           {
               checkFee = 10.00 + (0.1 * checks);
           }
               else if (checks >= 20 && checks < 40)
               {
                   checkFee = 10.00 + (0.08 * checks);
               }
               else if (checks >= 40 && checks < 60)
               {
                   checkFee = 10.00 + (0.06 * checks);
               }
               else
               {
                   checkFee = 10.00 + (0.04 * checks);
               }
       }
       public void setOverdraft()
       {  
           if (balance < 400.0)
           {
               overdraftFee = 15;
           }
           else
               overdraftFee = 0;
       }
       public double getOverdraft()
       {
           return overdraftFee;
       }
       public double getFees()
       {
           setOverdraft();
           return checkFee + overdraftFee;
       }
       public double getBalance()
       {
           setOverdraft();
           return balance - checkFee - overdraftFee;
       }
   public static void main(String[] args) throws IOException
   {
       String input;
      
       HelloWorld account = new HelloWorld();
      
       DecimalFormat formatter = new DecimalFormat("#0.00");
      
       InputStreamReader reader = new InputStreamReader(System.in);
       BufferedReader keyboard = new BufferedReader(reader);
      
       System.out.print("How many checks did you write this month?");
       input = keyboard.readLine();
       account.setFees(Integer.parseInt(input));
      
      
      
       System.out.println("The fees you incurred this month are $" + formatter.format(account.getFees()) + " ");
       System.out.println("Your leftover balance is $" + formatter.format(account.getBalance()));
   }
   }

B.


import java.util.Scanner; // Needed for the Scanner class

public class Chpt3Number7 {
   public static void main(String [] args)    {
       String name1, name2, name3, temp;

       // Create a Scanner object to read input.
       Scanner keyboard = new Scanner(System.in);

       System.out.print("What is the first name? ");
       name1 = keyboard.nextLine();

       System.out.print("What is the second name? ");
       name2 = keyboard.nextLine();

       System.out.print("What is the third name? ");
       name3 = keyboard.nextLine();

       if (name1.charAt(0) > name2.charAt(0)) {
           temp = name1;
           name1 = name2;
           name2 = temp;
       }

       if (name1.charAt(0) > name3.charAt(0)) {
           temp = name1;
           name1 = name3;
           name3 = temp;
       }

       if (name2.charAt(0) > name3.charAt(0)) {
           temp = name2;
           name2 = name3;
           name3 = temp;
       }

       System.out.println();
       System.out.println(name1);
       System.out.println(name2);
       System.out.println(name3);

   }
}

output

What is the first name? charlie                                                                                                                             
What is the second name? lesle                                                                                                                              
What is the third name? andy                                                                                                                                
                                                                                                                                                            
andy                                                                                                                                                        
charlie                                                                                                                                                     
lesle