inital commit

This commit is contained in:
gabriel venberg 2021-03-26 22:45:38 -05:00
commit aa37ae1eec
55 changed files with 3927 additions and 0 deletions

View file

@ -0,0 +1,65 @@
/**
* BankAccount class that represents a real world entity Bank Account. It supports deposit, withdrawal
* and checking balance operations.
*
* @author Pratap Kotala
* @version 9/23/2014
*/
public class BankAccount
{
//instance variable balance to store the balance amount information
private double balance;
/**
* Default constructor for objects of class BankAccount which initializes balance to zero.
*/
public BankAccount()
{
// initialise instance variables
balance = 0;
}
/**
* Constructor for objects of class BankAccount which initializes balance to amount.
*/
public BankAccount(double amount)
{
balance = amount;
}
/**
* getBalance() method returns the current balance
*
* @param no parameter
* @return double
*/
public double getBalance()
{
return balance;
}
/**
* deposit() method adds the amount to the current balance
*
* @param double amount
* @return void
*/
public void deposit(double amount)
{
balance += amount;
}
/**
* withdraw() method reduces the current balance by amount
*
* @param double amount
* @return void
*/
public void withdraw(double amount)
{
if (amount > balance)
throw new IllegalArgumentException("insufficient balance");
else
balance -= amount;
}
}

View file

@ -0,0 +1,44 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
* BankAccountTest program created for CS1 class.
* @author toric
*/
public class BankAccountTest {
public static void main(String[] args) {
//initalize the first account
BankAccount account1 = new BankAccount();
//inital deposit
account1.deposit(1000);
//print amount
System.out.println("account 1 has $"+account1.getBalance());
//withdraw
account1.withdraw(250);
//second account
BankAccount account2 = new BankAccount(500);
//print balance
System.out.println("account 2 has $"+account2.getBalance());
//withdraw 100.
account2.withdraw(100);
//link the two accounts.
account2 = account1;
//deposit
account1.deposit(50);
System.out.println("account 1 has $"+account1.getBalance());
System.out.println("account 2 has $"+account2.getBalance());
}
}

51
lab05/src/StringTest.java Normal file
View file

@ -0,0 +1,51 @@
/*
* Copyright (C) 2020 Gabriel Venberg
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* made for lab05
* @author toric
*/
public class StringTest {
public static void main(String[] args) {
//inital assignment
String string1 = new String("Hi");
String string2 = new String("Hello World");
//finding the lengh of the two strings
System.out.println("string1 is "+string1.length()+" characters long");
System.out.println("string1 is "+string2.length()+" characters long");
//find the first o in both strings
System.out.println("the first o in string1 is at position "+string1.indexOf("o"));
System.out.println("the first o in string2 is at position "+string2.indexOf("o"));
//find the last o in each string
System.out.println("the last o in string1 is at position "+string1.lastIndexOf("o"));
System.out.println("the last o in string2 is at position "+string2.lastIndexOf("o"));
//use substring() to make a variable containing "world"
String substring = string2.substring(6);
System.out.println("string2 starting with the 6th character is "+substring);
//string2 all lowercase
System.out.println("string2 in all lowercase is "+string2.toLowerCase());
//string2 to all uppercase
System.out.println("string2 in all uppercase is "+string2.toUpperCase());
}
}