1. Introducing Learn Java and the DrJava IDE (Integrated Development Environment) - Learn Java

preview_player
Показать описание
Learn Java

Learn Java

Thanks 😊
Рекомендации по теме
Комментарии
Автор

You've always been my favorite "programming teacher" youtuber. You guide people through it very well and I've gone through all your videos multiple times to give my self a refresher on different coding languages. Thank you :)

avian
Автор

Hi my name is Antony from Kenya and I follow your videos and like them so much because they have taught me alot. I have a request can you please do a video on JFrames?

antonyfwende
Автор

As a Java Trainer i can say, your way of teaching is very good. Keep it up Man..

manishjangra
Автор

Thank you so much for uploading and sharing your talent, You are one of the very best teacher i have come across on you tube and Bucky Roberts, John Purcell too
I wish I can donate money toward your contribution for helping all beginners and advanced Java Student, But i do not have any bitCoin account
if any other way please let me know and if you have your lectuers on CD as I am not always online
Kindest regards
Wishing you the very best of luck as a top teacher

mofrehsarhan
Автор

import java.util.Scanner;

/**
This program demonstrates static methods
*/

public class Geometry
{
public static void main (String [] args)
{
int choice; //the user's choice
double value = 0; //the value returned from the method
char letter; //the Y or N from the user's decision to exit
double radius; //the radius of the circle
double length; //the length of the rectangle
double width; //the width of the rectangle
double height; //the height of the triangle
double base; //the base of the triangle
double side1; //the first side of the triangle
double side2; //the second side of the triangle
double side3; //the third side of the triangle

//create a scanner object to read from the keyboard
Scanner keyboard = new Scanner (System.in);

//do loop was chose to allow the menu to be displayed first
do
{
//call the printMenu method

choice = keyboard.nextInt();

switch (choice)
{
case 1:
System.out.print("Enter the radius of the circle: ");
radius = keyboard.nextDouble();
//call the circleArea method and store the result in the value variable

System.out.println("The area of the circle is " + value);
break;
case 2:
System.out.print("Enter the length of the rectangle: ");
length = keyboard.nextDouble();
System.out.print("Enter the width of the rectangle: ");
width = keyboard.nextDouble();
//call the rectangleArea method and store the result in the value variable

System.out.println("The area of the rectangle is " + value);
break;
case 3:
System.out.print("Enter the height of the triangle: ");
height = keyboard.nextDouble();
System.out.print("Enter the base of the triangle: ");
base = keyboard.nextDouble();
//call the triangleArea method and store the result in the value variable

System.out.println("The area of the triangle is " + value);
break;
case 4:
System.out.print("Enter the radius of the circle: ");
radius = keyboard.nextDouble();
//call the circumference method and store the result in the value variable

System.out.println("The circumference of the circle is " + value);
break;
case 5:
System.out.print("Enter the length of the rectangle: ");
length = keyboard.nextDouble();
System.out.print("Enter the width of the rectangle: ");
width = keyboard.nextDouble();
//call the perimeter method and store the result in the value variable

System.out.println("The perimeter of the rectangle is " + value);
break;
case 6:
System.out.print("Enter the length of side 1 of the triangle: ");
side1 = keyboard.nextDouble();
System.out.print("Enter the length of side 2 of the triangle: ");
side2 = keyboard.nextDouble();
System.out.print("Enter the length of side 3 of the triangle: ");
side3 = keyboard.nextDouble();
//call the perimeter method and store the result in the value variable

System.out.println("The perimeter of the triangle is " + value);
break;
default:
System.out.println("You did not enter a valid choice.");
}
keyboard.nextLine(); //consumes the new line character after the number
System.out.println("Do you want to exit the program (Y/N)?: ");
String answer = keyboard.nextLine();
letter = answer.charAt(0);
}while (letter != 'Y' && letter != 'y');
}
}

imuvast
Автор

would be awesome if you explain and slove this one too .


9. BankAccount and SavingsAccount Classes Design an abstract class named BankAccount to hold the following data for a bank account:


• Balance


• Number of deposits this month


• Number of withdrawals


• Annual interest rate


The class should have the following methods:


Constructor:


The constructor should accept arguments for the balance and annual interest rate.


deposit:


A method that accepts an argument for the amount of the deposit. The method should add the argument to the account balance. It should also increment the variable holding the number of deposits.


withdraw:


A method that accepts an argument for the amount of the withdrawal. The method should subtract the argument from the balance. It should also increment the variable holding the number of withdrawals.


calcInterest:


A method that updates the balance by calculating the monthly inter-est earned by the account, and adding this interest to the balance. This is performed by the following formulas:


Monthly Interest Rate = (Annual Interest Rate / 12)


Monthly Interest = Balance * Monthly Interest Rate


Balance = Balance + Monthly Interest


monthlyProcess: A method that calls the calcInterest method, and then sets the variables that hold the number of withdrawals, number of deposits to zero.


Next, design a SavingsAccount class that extends the BankAccount class. The SavingsAccount class should have a status field to represent an active or inactive account. If the balance of a savings account falls below $25, it becomes inactive. (The status field could be a boolean variable.) No more withdrawals may be made until the balance is raised above $25, at which time the account becomes active again.


The savings account class should have the following methods:


withdraw: A method that determines whether the account is inactive before a withdrawal is made. (No withdrawal will be allowed if the account is not active.) A withdrawal is then made by calling the superclass version of the method.


After the superclass method is called, this method checks the num-ber of withdrawals. If the number of withdrawals for the month is more than 4, a service charge of $1 for each withdrawal above 4 is from the balance. (Don’t forget to check the account balance after the service charge is taken. If the balance falls below $25, the account becomes inactive.)


deposit: A deposit is then made by calling the superclass version of the method. If the account is inactive and the deposit brings the balance above $25, the account becomes active again.


monthlyProcess:


Calls the super class monthly process and displays the final balance.


Please make sure that your classes throw appropriate exceptions when an attempt is made to insert invalid data.





Please check the Test cases for more information on requirements and input/output message format.


Plase note that the test input that your program will be tested might be different from the ones shown below. For exact test input data, please refer to test cases in mimir.


Test Case1(Testing Validations):


Enter beginning balance :$1000
Enter interest rate(whole number) :%9
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
X
Invalid choice. Try again


Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
D
Enter the amount you want to Deposit :$-1
Error: Must enter positive value


Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
W
Enter the amount you want to withdraw :$-1
Error: Must enter positive value


Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
B
Your Balance is: 1000.00
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
M
Your Balance after Monthly process is: 1007.50
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
E
Balance : $1007.50
Thank you. Bye


Test Case2(Testing Deposit functionality):


Enter beginning balance :$100
Enter interest rate(whole number) :%9
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
D
Enter the amount you want to Deposit :$10
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
D
Enter the amount you want to Deposit :$10
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
D
Enter the amount you want to Deposit :$100
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
D
Enter the amount you want to Deposit :$500
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
D
Enter the amount you want to Deposit :$600
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
B
Your Balance is: 1320.00
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
M
Your Balance after Monthly process is: 1329.90
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
E
Balance : $1329.90
Thank you. Bye


Test Case3(Testing Withdrawal. Please study this in detail and pay attention to minute details):


Enter beginning balance :$100
Enter interest rate(whole number) :%9
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
D
Enter the amount you want to Deposit :$100
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
W
Enter the amount you want to withdraw :$20
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
W
Enter the amount you want to withdraw :$20
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
W
Enter the amount you want to withdraw :$20
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
W
Enter the amount you want to withdraw :$20
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
B
Your Balance is: 120.00
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
W
Enter the amount you want to withdraw :$80
You have exceeded monthly limit of withdrawals. Fee of $1 charged


Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
B
Your Balance is: 39.00
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
W
Enter the amount you want to withdraw :$15
Your balance is less than minimum balance. Your account is now INACTIVE
You have exceeded monthly limit of withdrawals. Fee of $1 charged


Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
B
Your Balance is: 23.00
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
D
Enter the amount you want to Deposit :$3
Your account is now ACTIVE


Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
B
Your Balance is: 26.00
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
W
Enter the amount you want to withdraw :$1
Your balance is less than minimum balance. Your account is now INACTIVE
You have exceeded monthly limit of withdrawals. Fee of $1 charged


Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
B
Your Balance is: 24.00
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
D
Enter the amount you want to Deposit :$10
Your account is now ACTIVE


Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
B
Your Balance is: 34.00
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
W
Enter the amount you want to withdraw :$5
You have exceeded monthly limit of withdrawals. Fee of $1 charged


Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
B
Your Balance is: 28.00
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
D
Enter the amount you want to Deposit :$100
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
D
Enter the amount you want to Deposit :$1000
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
M
Your Balance after Monthly process is: 1136.46
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
E
Balance : $1136.46
Thank you. Bye


Test Case 4(Validation)


Enter beginning balance :$1000
Enter interest rate(whole number) :%9
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
W
Enter the amount you want to withdraw :$1200
ERROR: Transaction declined!! This transaction will cause overdraft or zero balance
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
B
Your Balance is: 1000.00
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit
M
Your Balance after Monthly process is: 1007.50
Enter D to deposit
Enter W to Withdraw
Enter B for Balance
Enter M for Monthly Process
Enter E to Exit

rezaarian
Автор

Hi Kay, Please can I get your email....

momodoujah
join shbcf.ru