Question

In: Computer Science

Assignment Overview This assignment will give you practice with interactive programs and if/else statements. Part 1:...

Assignment Overview This assignment will give you practice with interactive programs and if/else statements.

Part 1: User name Generator Write a program that prompts for and reads the user’s first and last name (separately). Then print a string composed of the first letter of the user’s first name, followed by the first five characters of the user’s last name, followed by a random number in the range 10 to 99. Assume that the last name is at least five letters long. Similar algorithms are sometimes used to generate usernames for new computer accounts. CLASS NAME. Your program class should be called UserNameGenerator.java. Sample run: Enter your first name: William Enter your last name: Henry Username: WHenry88 Part 2: Bank Charges [20 points] 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 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. CLASS NAME. Your program class should be called BankCharges.java. Sample run 1: Enter the number of checks written this month: 30 The total fees are $12.40 Sample run 2: Enter the number of checks written this month: 30 The total fees are $12.40

Sample run 3: Enter the number of checks written this month: 45 The total fees are $12.70

Sample run 4: Enter the number of checks written this month: 70 The total fees are $12.80 ______________________________________________________________

Rules:

 For this assignment you are limited to the language features in Chapters 1 through 4; you are not allowed. (The text is Intro to Java 10th edition Y. Liang) to use more advanced features to solve the problem. Please do not use Java features that are not covered in lecture or the textbook.

 Use class constants as appropriate to represent important fixed data values in your program.

 You are required to properly indent your code and will lose points if you make significant indentation mistakes. You should also use whitespace properly to make your program more readable, such as between operators and their operands, between parameters, and blank lines between groups of statements or methods.

 Java's naming standards about the format of ClassNames, VariableNames, and CONSTANT_NAMES.

 Include a comment at the beginning of your program with basic information.

 You should use at least one switch statement or at least one multi-way if-statement (using "else if").

 Much of your code will involve conditional execution with if and if/else statements. Part of your grade will come from using these statements appropriately.

 Notice that all real numbers output by the program are printed with no more than 2 digits after the decimal point. To achieve this, you may use the System.out.printf method as follows. // print exam score, rounded to 2 decimal places System.out.printf("%.2f", ExamScore);

Solutions

Expert Solution

Hi,

Please see below the Java classes. Please comment for any queries/ feedbacks.

Thanks,

Anita

UserNameGenerator.java

import java.util.Random;
import java.util.Scanner;


public class UserNameGenerator {
   //Minimum and Maximum Constants for for Random number generation
   public static final int MIN = 10;
   public static final int MAX = 99;

   public static void main(String [] args){
       String FirstName;
       String LastName;
       String UserName;

       Scanner scan = new Scanner(System.in);
       System.out.println("Enter your first name: ");
       FirstName = scan.nextLine();
       System.out.println("Enter your last name: ");
       LastName = scan.nextLine();

       UserName = generateUserName(FirstName,LastName);

       System.out.println("Username: "+UserName);

   }

   public static String generateUserName(String firstName, String lastName){
       int random = 0;
       Random r = new Random();
       String userName = "";
       //1.First letter of First Name
       userName = firstName.substring(0, 1);

       //Getting first 5 characters of lastName
       userName = userName + lastName.substring(0, 5);

       //Fenerating Random number between 10 an 99
       random = r.nextInt(MAX-MIN) + MIN;
       userName = userName + random;

       return userName;

   }

}

Sample output:

Enter your first name:
William
Enter your last name:
Henry
Username: WHenry95

BankCharges.java

import java.util.Scanner;


public class BankCharges {
   //Fee Constants
   public static final double BASE_FEE = 10;
   public static final double LESS_THAN_TWENTY_FEE = .10;
   public static final double TWENTY_THIRTYNINE_FEE = .08;
   public static final double FOURTY_FIFTYNINE_FEE = .06;
   public static final double SIXTY_OR_MORE_FEE = .04;

   public static void main(String[] args){
       String NoOfChecksStr = "";
       int NoOfChecks = 0;
       double fee = 0;
       Scanner scan = new Scanner(System.in);
       System.out.println("Enter the number of checks written this month: ");
       NoOfChecksStr = scan.nextLine();

       NoOfChecks = Integer.valueOf(NoOfChecksStr);


       //Calculating Fee based on the No of checks
       if(NoOfChecks < 20){
           fee = BASE_FEE + (NoOfChecks * LESS_THAN_TWENTY_FEE);
       }
       else if(NoOfChecks>=20 || NoOfChecks<40 ){
           fee = BASE_FEE + (NoOfChecks * TWENTY_THIRTYNINE_FEE);
       }
       else if(NoOfChecks>=40 || NoOfChecks<60 ){
           fee = BASE_FEE + (NoOfChecks * FOURTY_FIFTYNINE_FEE);
       }
       else if(NoOfChecks>=60 ){
           fee = BASE_FEE + ( NoOfChecks * SIXTY_OR_MORE_FEE);
       }

       System.out.printf("The total fees are %.2f", fee);

   }

}

Sample outputs:


Enter the number of checks written this month:
30
The total fees are 12.40


Related Solutions

Assignment Overview IN C++ This assignment will give you practice with numerical calculations, simple input/output, and...
Assignment Overview IN C++ This assignment will give you practice with numerical calculations, simple input/output, and if-else statements. Candy Calculator [50 points] The Harris-Benedict equation estimates the number of calories your body needs to maintain your weight if you do no exercise. This is called your basal metabolic rate or BMR. The calories needed for a woman to maintain her weight is: BMR = 655 + (4.3 * weight in pounds) + (4.7 * height in inches) - (4.7 *...
Python code Assignment Overview In this assignment you will practice with conditionals and loops (for). This...
Python code Assignment Overview In this assignment you will practice with conditionals and loops (for). This assignment will give you experience on the use of the while loop and the for loop. You will use both selection (if) and repetition (while, for) in this assignment. Write a program that calculates the balance of a savings account at the end of a period of time. It should ask the user for the annual interest rate, the starting balance, and the number...
Programming Assignment #3: SimpleFigure and CirclesProgram Description:This assignment will give you practice with value...
Programming Assignment #3: SimpleFigure and CirclesProgram Description:This assignment will give you practice with value parameters, using Java objects, and graphics. This assignment has 2 parts; therefore you should turn in two Java files.You will be using a special class called DrawingPanel written by the instructor, and classes called Graphics and Color that are part of the Java class libraries.Part 1 of 2 (4 points)Simple Figure, or your own drawingFor the first part of this assignment, turn in a file named...
This assignment is 2 programs demonstrating IF statements and Decisions. Program 1 Write a program that...
This assignment is 2 programs demonstrating IF statements and Decisions. Program 1 Write a program that asks a user for a temperature for two storage containers for a spaceship filled with water and oxygen. The program should tell if either is ice and if either is boiling. Numbers to use for your tests The Freezing point of water is 32 and the boiling point is 212. The Freezing point of oxygen is -362 and the boiling point is -306. Program...
The goal of this part is to give you a chance to practice working through the...
The goal of this part is to give you a chance to practice working through the steps of calculating variance. Use the table of scores (X values) below to complete the following calculations. Assume the data in the table represents a sample, not a population. Use the extra columns in the table to show your work. X 20 22 18 15 21 Question 2.1 (0.5 points) – Calculate the deviation score for each x value Question 2.2 (0.5 points) –...
The purpose of this assignment is to test your familiarity with Java I/O statements and if-else statements.
ObjectiveThe purpose of this assignment is to test your familiarity with Java I/O statements andif-else statements. This assignment also tests your understanding of the basics of Javaprogramming and execution, like top-down control flows, translating the logical solutionto a problem into code, and integrating the new concepts you just learned with theolder concepts, including data types and variables, declaration, initialization andassignments, arithmetic operators, etc.Please submit your source code (i.e. your java file) on Canvas under HW1.ProblemIt’s the year 2030 and H&R...
1.- In this assignment you will implement a simulation of the interaction of user programs with...
1.- In this assignment you will implement a simulation of the interaction of user programs with the OS to execute an I/O operation on two different devices. User programs: User programs will communicate with DOIO (OS) to request an I/O operation. (This will simulate a system call) User programs will give to DOIO three parameters: User id, device number (dev is a random number in the range 1 and 2 that represents device one or device two) and an address...
The goal of this assignment is to write five short Java/Pyhton programs to gain practice with...
The goal of this assignment is to write five short Java/Pyhton programs to gain practice with expressions, loops and conditionals. Boolean and integer variables and Conditionals. Write a program Ordered.java that reads in three integer command-line arguments, x, y, and z.   Define a boolean variable isOrdered whose value is true if the three values are either in strictly ascending order  (x < y < z) or in strictly descending order  (x > y > z), and false otherwise. Print out the variable isOrdered...
The C++ question: This part of the assignment will give you a chance to perform some...
The C++ question: This part of the assignment will give you a chance to perform some simple tasks with pointers. The instructions below are a sequence of tasks that are only loosely related to each other. Start the assignment by creating a file named pointerTasks.cpp with an empty main function, then add statements in main() to accomplish each of the tasks listed below. Some of the tasks will only require a single C++ statement, others will require more than one....
For this assignment, I'm going to give a series of problem statements and you need to...
For this assignment, I'm going to give a series of problem statements and you need to state whether the problem would be more appropriately solved with a linear or logistic regression. You also have to give a short defense of why this is the correct regression for each one (only need a sentence or two for each). I have a dataset of soil sample attributes (acidity, density, clay content, etc.) and whether Kentucky bluegrass successfully grew in the soil. I...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT