2. Car Class
3. Personal Information Class
Note: only created one instance but printing is not necessary..
4. RetailItem Class
5. payroll Class
6. TestScore Class
7. Circle Class
8. A Game of Twenty One (skipped just cause I dont want to read how it works/ cards games bore me to death) Imagine saying that to your boss or your professor.
9. Freezing and Boiling Points
10. Saving Account Class.
11. Deposit and Withdrawal files.
import java.util.Scanner;
public class SavingAccount {
private double interestRate;
private static double balance;
public SavingAccount(double Doru)
{
this.balance=Doru;
}
public double getBalance(){return balance;}
public void setBalance(double e){this.balance=e;}
public static double withdraw(double doru)
{
balance = balance-doru;
System.out.println("Your balance is : $" + balance);
return balance;
}
public static double deposit(double doru)
{
balance = balance + doru;
System.out.println("Your balance is now : $"+ balance);
return balance;
}
public static void interest(double doru, double interest)
{
double interest1 = interest/100;
double month= interest1/12;
double calc = month*doru + doru;
System.out.println("The interest for this month is : "+ calc);
}
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter your starting balance : $");
double balanceStart =input.nextDouble();
SavingAccount a = new SavingAccount(balanceStart);
a.setBalance(balanceStart);
System.out.print("Enter the number of months: ");
int months = input.nextInt();
System.out.print("Enter the annual interest rate : ");
double rate = input.nextDouble();
for(int i=1; i<=months; i++)
{
double depositer, withdrawer = 0.0;
System.out.print("Enter deposit amount for month no#"+ i + " :");
depositer = input.nextDouble();
deposit(depositer);
System.out.print("Enter withdraw amount for month no#"+ i + " :");
withdrawer=input.nextDouble();
withdraw(withdrawer);
interest(a.getBalance(), rate);
}
}
}
Coin ones the other ones didn't get uploaded due to internet connection and I overwrote the program so
/**
*
* @author Niilma M.
*/
import java.util.*;
public class Coin {
private static String sideup;
;
private static double balance;
public Coin(){
int num;
Random number = new Random();
num = number.nextInt(2)+1;
if(num==1)
{
sideup ="heads";
}
else if(num==2)sideup="tails";
else System.out.println("Wrong random input");
}
public void toss(double v)
{
int randomer=0;
Random randomObj= new Random();
randomer = randomObj.nextInt(2)+1;
if(randomer==1)
{
sideup="heads";
balance = balance + v;
}
else {sideup="tails";}
}
public static String getSideUp()
{
return sideup;
}
public static void main(String[] args)
{
Coin quarter=new Coin();
Coin dime = new Coin();
Coin nickel = new Coin();
while (balance<=1.0)
{
quarter.toss(.25);
dime.toss(.10);
nickel.toss(.05);
}
if(balance==1.0)
{
System.out.println("Winner");
}
else
{
System.out.println("You lose..");
System.out.println("Balance is $"+ balance);
}
}
}
No comments:
Post a Comment