Question

In: Computer Science

/** Create a method as instructed below and then call it appropriately. */ import java.util.Scanner; public...

/**
Create a method as instructed below and then call it appropriately.
*/

import java.util.Scanner;

public class BankCharges
{
public static void main(String[] args)
{
//Variable declarations
int numChecks;
double perCheckFee;
double totalFee;
double totalFeesAllAccounts = 0; //accumulator
int numAccounts;
  
//Constant declarations for base fee and per check fees
final double BASE_FEE = 10.0;
final double LESS_THAN_20_FEE = 0.10;
final double TWENTY_TO_THIRTYNINE_FEE = 0.08;
final double FORTY_TO_FIFTYNINE_FEE = 0.06;
final double SIXTY_OR_MORE_FEE = 0.04;
  
// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
  
//Getting the number of accounts
System.out.print("How many accounts do you have?: ");
numAccounts = keyboard.nextInt();
  
//validating number of accounts
while (numAccounts <= 0)
{
System.out.println("There must be at least 1 account. Try again: ");
numAccounts = keyboard.nextInt();
}
  
//Running total loop to calculate fees for multiple accounts
for(int i = 0; i < numAccounts; i++)
{
// Get the number of checks written.
System.out.print("Enter number of checks for account " + (i + 1) + ": ");
numChecks = keyboard.nextInt();
  
// Determine the appropriate per-check fee.
if (numChecks < 20)
perCheckFee = LESS_THAN_20_FEE;

else if (numChecks <= 39)
perCheckFee = TWENTY_TO_THIRTYNINE_FEE;
  
else if (numChecks <= 59)
perCheckFee = FORTY_TO_FIFTYNINE_FEE;
  
else
perCheckFee = SIXTY_OR_MORE_FEE;

//Calculate the total fee
totalFee = BASE_FEE + numChecks * perCheckFee;
  
//Totaling the fees from multiple accounts
totalFeesAllAccounts += totalFee;

}//end for loop

//Display the sum of the fees of all the accounts
System.out.printf("The sum of the fees of %d accounts is $%,.2f\n", numAccounts, totalFeesAllAccounts);
  
}//end main

/**
Write a method here that accepts the number of accounts and the sum of the fees of all the accounts.
This method rather than main should print the message that displays these values.
*/
  

}//end class

Solutions

Expert Solution

/**
Create a method as instructed below and then call it appropriately.
*/

import java.util.Scanner;

public class BankCharges
{
public static void main(String[] args)
{
//Variable declarations
int numChecks;
double perCheckFee;
double totalFee;
double totalFeesAllAccounts = 0; //accumulator
int numAccounts;
  
//Constant declarations for base fee and per check fees
final double BASE_FEE = 10.0;
final double LESS_THAN_20_FEE = 0.10;
final double TWENTY_TO_THIRTYNINE_FEE = 0.08;
final double FORTY_TO_FIFTYNINE_FEE = 0.06;
final double SIXTY_OR_MORE_FEE = 0.04;
  
// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
  
//Getting the number of accounts
System.out.print("How many accounts do you have?: ");
numAccounts = keyboard.nextInt();
  
//validating number of accounts
while (numAccounts <= 0)
{
System.out.println("There must be at least 1 account. Try again: ");
numAccounts = keyboard.nextInt();
}
  
//Running total loop to calculate fees for multiple accounts
for(int i = 0; i < numAccounts; i++)
{
// Get the number of checks written.
System.out.print("Enter number of checks for account " + (i + 1) + ": ");
numChecks = keyboard.nextInt();
  
// Determine the appropriate per-check fee.
if (numChecks < 20)
perCheckFee = LESS_THAN_20_FEE;

else if (numChecks <= 39)
perCheckFee = TWENTY_TO_THIRTYNINE_FEE;
  
else if (numChecks <= 59)
perCheckFee = FORTY_TO_FIFTYNINE_FEE;
  
else
perCheckFee = SIXTY_OR_MORE_FEE;

//Calculate the total fee
totalFee = BASE_FEE + numChecks * perCheckFee;
  
//Totaling the fees from multiple accounts
totalFeesAllAccounts += totalFee;

}//end for loop
displayMessage(numAccounts,totalFeesAllAccounts);

}//end main

/**
Write a method here that accepts the number of accounts and the sum of the fees of all the accounts.
This method rather than main should print the message that displays these values.
*/
public static void displayMessage(int numAccounts,double totalFeesAllAccounts){
//Display the sum of the fees of all the accounts
System.out.printf("The sum of the fees of %d accounts is $%,.2f\n", numAccounts, totalFeesAllAccounts);
}

  

}//end class


Related Solutions

only JAVA code /** Create a method as instructed below and then call it appropriately. */...
only JAVA code /** Create a method as instructed below and then call it appropriately. */ import java.util.Scanner; public class MoreBankCharges { //Constant declarations for base fee and per check fees //Class scope so constants are accessible by all methods static final double BASE_FEE = 10.0; static final double LESS_THAN_20_FEE = 0.10; static final double TWENTY_TO_THIRTYNINE_FEE = 0.08; static final double FORTY_TO_FIFTYNINE_FEE = 0.06; static final double SIXTY_OR_MORE_FEE = 0.04; public static void main(String[] args) { //Variable declarations int numChecks;...
create code for deletestudentbyID Number for choice == 4 package courseecom616; import java.util.Scanner; import java.util.ArrayList; public...
create code for deletestudentbyID Number for choice == 4 package courseecom616; import java.util.Scanner; import java.util.ArrayList; public class CourseeCOM616 {        private String courseName;     private String[] studentsName = new String[1];     private String studentId;        private int numberOfStudents;        public CourseeCOM616(String courseName) {         this.courseName = courseName;     }     public String[] getStudentsName() {         return studentsName;     }     public int getNumberOfStudents() {         return numberOfStudents;     }     public String getStudentId() {         return studentId;    ...
import java.util.Scanner; public class MonthsOnAndAfter { // You will need to write a method that makes...
import java.util.Scanner; public class MonthsOnAndAfter { // You will need to write a method that makes this // code compile and produce the correct output. // YOU MUST USE switch! // As a hint, you should not have to use the name of each // month more than once. // TODO - write your code below this comment. // DO NOT MODIFY main! public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter month (0-11): "); int month...
import java.util.Scanner; public class Months { // You will need to write a method that makes...
import java.util.Scanner; public class Months { // You will need to write a method that makes this // code compile and produce the correct output. // YOU MUST USE switch! // TODO - write your code below this comment. // DO NOT MODIFY main! public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter month (0-11): "); int month = input.nextInt(); String output = monthAsString(month); System.out.println(output); } }
import java.util.Scanner; public class LetterGrade { // The method you write will return a String representing...
import java.util.Scanner; public class LetterGrade { // The method you write will return a String representing a letter // grade (e.g., "A", "A-", "B+", etc.). // The letter grade is determined by the given percentage, according // to the scale specified on page 2 of the class syllabus (available // here: https://kyledewey.github.io/comp110-spring18/syllabus.pdf). // You may assume that the given percentage is between 0.0 and 100.0 // TODO - write your code below this comment.    public static String letterGrade(double percentage){...
Need to able to solve this method WITHOUT using ANY java libraries. ------------------------------ import java.util.Scanner; public...
Need to able to solve this method WITHOUT using ANY java libraries. ------------------------------ import java.util.Scanner; public class nthroot { public static void main(String[] args) { Scanner sc = new Scanner(System.in);    // Read n (for taking the nth root) int num = Integer.parseInt(sc.nextLine());    // Read number to take the nth root of int number = Integer.parseInt(sc.nextLine());    // Read the desired precision int precision = Integer.parseInt(sc.nextLine());    // Print the answer System.out.println(findnthRoot(number, num, precision)); }    private static String...
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Exercise { public static void main(String[] args) {...
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Exercise { public static void main(String[] args) { Scanner input=new Scanner(System.in); int[] WordsCharsLetters = {0,1,2}; while(input.hasNext()) { String sentence=input.nextLine(); if(sentence!=null&&sentence.length()>0){ WordsCharsLetters[0] += calculateAndPrintChars(sentence)[0]; WordsCharsLetters[1] += calculateAndPrintChars(sentence)[1]; WordsCharsLetters[2] += calculateAndPrintChars(sentence)[2]; } else break; } input.close(); System.out.println("Words: " + WordsCharsLetters[0]); System.out.println("Characters: " + WordsCharsLetters[1]); System.out.println("Letters: " + WordsCharsLetters[2]); } static int[] calculateAndPrintChars(String sentence) { int[] WCL = new int[3]; String[] sentenceArray=sentence.split(" "); WCL[0] = sentenceArray.length; int letterCount=0; for(int i=0;i<sentence.length();i++) { if(Character.isLetter(sentence.charAt(i))) letterCount++; } WCL[1]...
import java.util.Random; import java.util.Scanner; public class Compass { public Random r; public Compass(long seed){ r =...
import java.util.Random; import java.util.Scanner; public class Compass { public Random r; public Compass(long seed){ r = new Random(seed); }    public static String numberToDirection(int a){ if(a==0) return "North";    if(a==1) return "NorthEast"; if(a==2) return "East"; if(a==3) return "Southeast"; if(a==4) return "South"; if(a==5) return "Southwest"; if(a==6) return "West";    if(a==7) return "Northwest";    return "Invalid Direction" ; } public String randomDirection(){ return numberToDirection(r.nextInt()% 4 + 1); } public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter seed: ");...
import java.util.Random; import java.util.Scanner; public class Compass { // You will need to do the following:...
import java.util.Random; import java.util.Scanner; public class Compass { // You will need to do the following: // // 1.) Define a private instance variable which can // hold a reference to a Random object. // // 2.) Define a constructor which takes a seed value. // This seed will be used to initialize the // aforementioned Random instance variable. // // 3.) Define a static method named numberToDirection // which takes a direction number and returns a String // representing...
In this create a code that will drop a student by ID number //////////////////////////////////////////////////////////////////////// import java.util.Scanner;...
In this create a code that will drop a student by ID number //////////////////////////////////////////////////////////////////////// import java.util.Scanner; public class COurseCom666 {     private String courseName;     private String [] students = new String[1];     private int numberOfStudents;     public COurseCom666(String courseName) {         this.courseName = courseName;     }     public String[] getStudents() {         return students;     }     public int getNumberOfStudents() {         return numberOfStudents;     }     public String getCourseName() {         return courseName;     }     public void...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT