Tuesday, March 29, 2016

Chapter 6 Solutions 1-10 except the card game


1. Employee Class
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);
          
        }
    }

   

}




Monday, March 28, 2016

Chapter 5 solutions expect the prime numbers

1.showChar Method




2. Retail Price Calculator
4. Paint Estimator

5. Falling Distance
6. Celcius Temperature Table
7. Test Average and Grade

8. Conversion Program



9. Distance Travelled Modification

10. Stock Profit
12. Kinetic Energy
13. isPrime Method

skipped

14. Prime Number List
skipped will come back battery dying

15. Even/Odd Counter

16. Present Value


17. Rock Paper Scissor Game




18. ESP Game




15. Budget Analysis

Gonna skip the rest because random numbers are so boring.

14. Line Numbers

Book Title: From Control Structures through Objects by Tony Gaddis 
Solutions

13. File Head Display

Starting Out with Java: From Control Structures through Objects SOLUTIONS

Ugh i had done all the solutions but deleted the screen shots..