Write the following codes on Netbeans IDE 81 1 Write a java

Write the following codes on Netbeans IDE 8.1

1. Write a java program that creates 3 bank account objects. Each object contains the name of the account owner, the account number, and the current balance. For example, my first account object would be created as follows:bankAccount = new bankAccount(\"John Doe\", 1200, 350.00). Then, allow each account owner to enter a deposit. Then, calculate the interest in each account after the deposit. Decide on your own the interest rate. Then allow each account owner to withdraw some money from the account after the interest is applied. Then print out the account balance for each of the three users after the withdrawal.

2. We are going to revisit conditional statements. Write a java program with the following specifications. Suppose you gets paid $18.00 per hour if you work for 40 hours a week. If you work for more than 40 hours a week, you get paid twice the normal pay. Write a java program that asks you to enter the amount of hours you work in a given week, and calculates your pay for that week.

Let me help you out a little bit. You may have the following variable. final double hourlyrate = 18.00; final int regularHours = 40; You need another variable to calculate double pay. And of course you need to use Scanner input.

3. Write a java program that returns the minimum of 3 numbers. The name of your code must be min.java.

Solution

1)

BankAccount.java

public class BankAccount {
   //Declaring instance variables
   private String owner;
   private int account_number;
   private double balance;
  
   //Parameterized constructor
   public BankAccount(String owner, int account_number, double balance) {
       super();
       this.owner = owner;
       this.account_number = account_number;
       this.balance = balance;
   }
  
   //Setters and getters
   public String getOwner() {
       return owner;
   }
   public void setOwner(String owner) {
       this.owner = owner;
   }
   public int getAccount_number() {
       return account_number;
   }
   public void setAccount_number(int account_number) {
       this.account_number = account_number;
   }
   public double getBalance() {
       return balance;
   }
   public void setBalance(double balance) {
       this.balance = balance;
   }
  
   //This method with add the deposit amount to current balance
   public void deposit(double amount)
   {
       //Adding deposit to current balance
       this.balance=getBalance()+amount;
   }
  
   //This method will add interest to the current balance
   public void interestAmount(double interest_rate)
   {
       // adding interest to the current balance
       this.balance=getBalance()+getBalance()*(interest_rate/100);
   }
  
   //This method will subtract the amount from the current balance
   public void withdraw(double amount)
   {
       //subtracting the amount from the current balance
       this.balance=getBalance()-amount;
   }

}

_____________________________________________

DriverClass.java

public class DriverClass {

   public static void main(String[] args) {
       System.out.println(\"________Bank Account 1________\");
      
       //Creating BankAccount Object by passing the arguments
       BankAccount ba1 = new BankAccount(\"John Doe\", 1200, 350.00);
      
       //Getting the current balance in the account
       System.out.println(\"Balance :\"+ba1.getBalance());
      
       //Depositing the amount
       ba1.deposit(1000);
      
       //Getting the current balance in the account
       System.out.println(\"Balance After Depositing Amount:\"+ba1.getBalance());
      
       ba1.interestAmount(8);
      
       //Getting the current balance in the account
       System.out.println(\"Balance After Adding Interest Amount:\"+ba1.getBalance());
       ba1.withdraw(400);
      
       //Getting the current balance in the account
       System.out.println(\"Balance After Withdrawl :\"+ba1.getBalance());
      
       System.out.println(\"\ ________Bank Account 2________\");
       BankAccount ba2 = new BankAccount(\"John Miller\", 4537, 900.00);
      
       //Getting the current balance in the account
       System.out.println(\"Balance :\"+ba2.getBalance());
      
       //Calling deposit method by passing the amount as argument
       ba2.deposit(2000);
      
       //Getting the current balance in the account
       System.out.println(\"Balance After Depositing Amount:\"+ba2.getBalance());
      
       //Calling interestAmount() method
       ba2.interestAmount(7);
      
       //Getting the current balance in the account
       System.out.println(\"Balance After Adding Interest Amount:\"+ba2.getBalance());
      
       //Calling withDraw() method
       ba2.withdraw(600);
      
       //Getting the current balance in the account
       System.out.println(\"Balance After Withdrawl:\"+ba2.getBalance());
      
       System.out.println(\"\ ________Bank Account 3________\");
       BankAccount ba3 = new BankAccount(\"Kane Williams\", 4567, 800.00);
      
       //Getting the current balance in the account
       System.out.println(\"Balance :\"+ba3.getBalance());
      
       //Calling deposit method by passing the amount as argument
       ba3.deposit(400);
      
       //Getting the current balance in the account
       System.out.println(\"Balance After Depositing Amount:\"+ba3.getBalance());
      
       //Calling interestAmount() method
       ba3.interestAmount(9);
      
       //Getting the current balance in the account
       System.out.println(\"Balance After Adding Interest Amount:\"+ba3.getBalance());
      
       //Calling withDraw() method
       ba3.withdraw(300);
      
       //Getting the current balance in the account
       System.out.println(\"Balance After Withdrawl:\"+ba3.getBalance());
  

   }

}

___________________________________________

Output:

________Bank Account 1________
Balance :350.0
Balance After Depositing Amount:1350.0
Balance After Adding Interest Amount:1458.0
Balance After Withdrawl :1058.0

________Bank Account 2________
Balance :900.0
Balance After Depositing Amount:2900.0
Balance After Adding Interest Amount:3103.0
Balance After Withdrawl:2503.0

________Bank Account 3________
Balance :800.0
Balance After Depositing Amount:1200.0
Balance After Adding Interest Amount:1308.0
Balance After Withdrawl:1008.0

____________________________________________

2)

CalculateSalary.java

import java.util.Scanner;

public class CalculateSalary {
   //Declaring constants
   static final double PAY_RATE=18.00;
   static final int regularHours = 40;
   public static void main(String[] args) {
      
       //Declaring variables
       double pay = 0,weekly_pay;
       int working_hours;
      
       //Scanner class object is used to read the inputs entered by the user
       Scanner sc=new Scanner(System.in);
      
       //Getting the no of worked hours by an employee
       System.out.print(\"Enter No of Working Hours :\");
       working_hours=sc.nextInt();
      
       /* Checking if the working hours is less than 40
       * then this block of code will get executed
       */
       if(working_hours<40)
       {  
       //calculating weekly pay  
       pay=working_hours*PAY_RATE;
       }
       /* Checking if the working hours is equal to 40
       * then this block of code will get executed
       */
       else if(working_hours==40)
       {  
       //calculating weekly pay
       pay=regularHours*PAY_RATE;
       }
       /* Checking if the working hours is greater than 40
       * then this block of code will get executed
       */
       else if(working_hours>40)
       {  
       //calculating weekly pay  
       pay=(regularHours*PAY_RATE)+(working_hours-40)*PAY_RATE*2;
       }
      
       //Displaying the weekly pay
       System.out.println(\"Weekly Pay for \"+working_hours+\" @\"+PAY_RATE+\" per hour is :$\"+pay);
      

   }

}

___________________________________________

Output1:

Enter No of Working Hours :39
Weekly Pay for 39 @18.0 per hour is :$702.0

____________________________________________

Output2:

Enter No of Working Hours :40
Weekly Pay for 40 @18.0 per hour is :$720.0

____________________________________________

Output3:

Enter No of Working Hours :45
Weekly Pay for 45 @18.0 per hour is :$900.0

_____________________________________________

3)

package org.students;

import java.util.Scanner;

public class MaxOf3Nos {

   public static void main(String[] args) {
      
       //creating an integer array of size three
       int nums[]=new int[3];
      
       //Scanner class object is used to read the inputs entered by the user
       Scanner sc=new Scanner(System.in);
      
       //getting 3 numbers from the user and populating them into an array
       for(int i=0;i<3;i++)
       {
       //getting the numbers from the user  
       System.out.print(\"Enter Number \"+(i+1)+\":\");
       nums[i]=sc.nextInt();
       }      
      
       //assigning first element of an array to the variable min
       int min=nums[0];
      
      
       //this loop will calculate the minimum of three numbers
       for(int i=0;i<3;i++)
       {
       if(nums[i]<min)
       min=nums[i];
       }      
      
       //Displaying the minimum number
System.out.println(\"The Minimum of Three Numbers is \"+min);
   }

}

_____________________________________________

Output:

Enter Number 1:56
Enter Number 2:33
Enter Number 3:90
The Minimum of Three Numbers is 33

_________________________________________Thank You

Write the following codes on Netbeans IDE 8.1 1. Write a java program that creates 3 bank account objects. Each object contains the name of the account owner, t
Write the following codes on Netbeans IDE 8.1 1. Write a java program that creates 3 bank account objects. Each object contains the name of the account owner, t
Write the following codes on Netbeans IDE 8.1 1. Write a java program that creates 3 bank account objects. Each object contains the name of the account owner, t
Write the following codes on Netbeans IDE 8.1 1. Write a java program that creates 3 bank account objects. Each object contains the name of the account owner, t
Write the following codes on Netbeans IDE 8.1 1. Write a java program that creates 3 bank account objects. Each object contains the name of the account owner, t
Write the following codes on Netbeans IDE 8.1 1. Write a java program that creates 3 bank account objects. Each object contains the name of the account owner, t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site