Friday, December 12, 2014

Math C++

  Write a C++ program that creates the following functions:

 double Max (double Values[], int size);

 double Min (double Values[], int size);

 double calc Average(double Values[], int size);

 double calc Median(double Values[], int size);

double calc Standard Deviation (double Values[], int size);

 Write a driver program that creates an array with 11 values and calculates all of the preceding values. Display the values to the user. Create a second array that has 10 values and display all of the preceding values.

Note: You do not need to get input from the user. Must use the previous functions prototype.





#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

double calcMax (int arg[], int length)
{
    int maxValue = 0;
    for(int i = 0; i < length; i++)
        {
        if(arg[i] > maxValue)
        {
            maxValue = arg[i];
        }

        }
         cout << "The highest value is: " << maxValue<<endl;

}
double calcMin (int arg[], int length)
{
    int minValue = 1000;
    for(int i = 0; i < length; i++)
        {
        if(arg[i] < minValue)
        {
            minValue = arg[i];
        }

        }
        cout << "The minimum value is: " << minValue<<endl;

}
double calcAverage (int arg[], int length)
{
int sum=0;
for (int i=0; i<length; i++)
sum += arg[i];

cout << "The average value is: " << sum/length<<endl;


}
double calcMedian (int arg[], int length)
{
    sort(arg, arg + length);
    cout << "The new sorted array looks like this." << endl;
    cout << "=====================================" << endl;
    for (size_t i = 0; i != length; ++i)
        cout << arg[i] << " ";
{    double* dpSorted = new double[length];
    for (int i = 0; i < length; ++i) {
        dpSorted[i] = arg[i];
    }
    for (int i = length - 1; i > 0; --i) {
        for (int j = 0; j < i; ++j) {
            if (dpSorted[j] > dpSorted[j+1]) {
                double dTemp = dpSorted[j];
                dpSorted[j] = dpSorted[j+1];
                dpSorted[j+1] = dTemp;
            }
        }
    }

        double dMedian = 0.0;
    if ((length % 2) == 0) {
        dMedian = (dpSorted[length/2] + dpSorted[(length/2) - 1])/2.0;
    } else {
        dMedian = dpSorted[length/2];
    }
    delete [] dpSorted;
     cout << "                              " << endl;
     cout << "The median value is: " << dMedian<<endl;
 }
 }
double calcStandardDev (int arg[], int length)
{
double deviation;
double sum2;
double mean;
for ( int i = 0; i <=length; i++ )
{
sum2 += pow((arg[i]-mean),2);
}
deviation= sqrt(sum2/(length-1));
cout << "The Standard Deviation is : " <<deviation<<endl;
cout << "                              " << endl;
cout << "                              " << endl;
cout << "                              " << endl;
cout << "                              " << endl;

}

int main ()
{

    int number1 [] = {1,2,3,4,25,6,7,8,9,11,12};
    calcMax(number1, 11);
    calcMin(number1, 11);
    calcAverage(number1,11);
    calcMedian(number1, 11);
    calcStandardDev(number1,11);
    int number2 [] ={10,9,8,7,6,5,4,3,2,1,11};
    calcMax(number2, 10);
    calcMin(number2, 10);
    calcAverage(number2,10);
    calcMedian(number2, 10);
    calcStandardDev(number2,10);

  return 0;
}

Tuesday, December 2, 2014

C++ Pay problem


/////////////////////////////////////////////////////////////////////////////////////////////////////
// Program Description:Write a program that calculates the daily      //
////pay and total pay of a person who works for a penny the first       //
//day and their pay doubles every day after that. The program must //
// calculate the salary and not just output the pay. Use the                 //
//  following variables:                                                                        //
//                                                                                                          //
// Input:     days worked                                                                      //
// Processing: pay cubed + running total                                            //
// Output:     pay grid of money earned                                              //
///////////////////////////////////////////////////////////////////////////////////////////////////
#include<iostream>
#include <iostream>
#include <cmath>
using namespace std;
    int main ()
    {
        int days, maxValue = 0;
        float wages = 0;
        float totalpay = 0;
        float runningtotal = 0;

        cout <<"Please enter the number of days worked: ";

        cin >> maxValue;
        cout << "Day \t\tPay \t\tTotal Pay" <<endl;
        cout <<"----------------------------------------" <<endl;
         for (days = 1; days <= maxValue; days++)
        {
            if (days==1)
                {
                    wages = .01;
                    runningtotal = wages;
                    totalpay = .01;
                }
            else if (days==2)
                {
                    wages = wages + .01;
                    runningtotal = wages;
                    totalpay = .03;
                }
            else
                {
                    wages = ((wages) * (2));
                    runningtotal = wages;
                    totalpay = wages + runningtotal -.01;
                }
        cout <<days<<"\t\t"<<wages<<"\t\t"<< totalpay<< endl;
        }
        return 0;
    }

Friday, November 21, 2014

C++ Pointer Lab

Exercise 1: Declare 2 int variables x and y and 2 int* pointer variables p and q.  Set x to 2, y to 8, p to the address of x, and q to the address of y.  Then print the following information:
Exercise 2: Declare 3 int variables x, y, z and 3 int* pointer variables p, q, r.  Set x, y, z to three distinct values.  Set p, q, r to the addresses of x, y, z respectively.





/*
// Author:Zachary //
//                                                                               //
// Date:                    11/10/14 23:34                        //
//                                                                             //
// Input:  None                                                       //
 */

#include<iostream>
#include <algorithm>    // std::swap

using namespace std;
void Exone ()
//Exercise 1: Declare 2 int variables x and y and 2 int* pointer variables p and q.//
//Set x to 2, y to 8, p to the address //
//of x, and q to the address of y.  Then print the following information://
{
    int x,y;
int *p,*q;
    x=2;
y=8;
p=&x;
q=&y;
cout<<"--------------------Exercise 1:------------------"<<endl;
cout<<"-------------------------------------------------"<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<"The address of x is "<<&x<<" and the value of x is "<<x<<endl;//(1) The address of x and the value of x.
cout<<"The value of p is "<<p<<" and the value of *p is "<<*p<<endl;//(2) The value of p and the value of *p.
cout<<"The address of y is "<<&y<<" and the value of y is "<<y<<endl;//(3) The address of y and the value of y.
cout<<"The value of q is "<<q<<" and the value of *q "<<*q<<endl;//(4) The value of q and the value of *q.
cout<<"The address of p (not its contents!) is "<<&p<<endl;//(5) The address of p (not its contents!).
cout<<"The address of q (not its contents!) is "<<&q<<endl;//(6) The address of q (not its contents!).
}
void Extwo()
//Exercise 2: Declare 3 int variables x, y, z and 3 int* pointer variables p, q, r.  //
//Set x, y, z to three distinct values.  Set p, q, r to the addresses of x, y, z respectively.//
{
    {
        int x,y,z;
        int *p,*q,*r;
        x=1;
        y=2;
        z=3;
        p=&x;
        q=&y;
        r=&z;
        cout<<" "<<endl;

        cout<<" "<<endl;
        cout<<" "<<endl;
        cout<<" "<<endl;
        cout<<" "<<endl;
        cout<<" "<<endl;
        cout<<"--------------------Exercise 2:------------------"<<endl;
        cout<<"-------------------------------------------------"<<endl;
        cout<<" "<<endl;
        cout<<" "<<endl;
        //(1) Print with labels the values of x, y, z, p, q, r, *p, *q, *r.
        cout<<"value of x is "<<x<<endl;
        cout<<"value of y is "<<y<<endl;
        cout<<"value of z is "<<z<<endl;
        cout<<"value of p is "<<p<<endl;
        cout<<"value of q is "<<q<<endl;
        cout<<"value of r is "<<r<<endl;
        cout<<"value of *p is "<<*p<<endl;
        cout<<"value of *q is "<<*q<<endl;
        cout<<"value of *r is "<<*r<<endl;
        cout<<" "<<endl;
        cout<<" "<<endl;
        //(2) Print the message: Swapping values.
        cout<<"!!!!!!!SWAPPING VALUES!!!!!!"<<endl;
        cout<<" "<<endl;
        cout<<" "<<endl;
        //(3) Execute the swap code: z = x; x = y; y = z;
      std::swap(z,x);
      std::swap(x,y);
      std::swap(y,z);
      //(4) Print with labels the values of x, y, z, p, q, r, *p, *q, *r.
        cout<<"value of x is "<<x<<endl;
        cout<<"value of y is "<<y<<endl;
        cout<<"value of z is "<<z<<endl;
        cout<<"value of p is "<<p<<endl;
        cout<<"value of q is "<<q<<endl;
        cout<<"value of r is "<<r<<endl;
        cout<<"value of *p is "<<*p<<endl;
        cout<<"value of *q is "<<*q<<endl;
        cout<<"value of *r is "<<*r<<endl;
    }
}
int main()
{
Exone();
Extwo();
  return 0;
}//end main

Four by Four Array

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
const int ROW = 4;
const int COL = 4;
unsigned seed = time(0);
srand(seed);
int FourbyFour[ROW][COL] = {{1 + rand() % 10, 1 + rand() % 10, 1 + rand() % 10, 1 + rand() % 10},
{1 + rand() % 10, 1 + rand() % 10, 1 + rand() % 10, 1 + rand() % 10},
{1 + rand() % 10, 1 + rand() % 10, 1 + rand() % 10, 1 + rand() % 10},
{1 + rand() % 10, 1 + rand() % 10, 1 + rand() % 10, 1 + rand() % 10}};
int sum;
cout << endl;

for (int x = 0; x < ROW; x++)
{
for (int y = 0; y < COL; y++)
{
cout << "  " << setw(2) << FourbyFour[x][y] << "  ";
}

cout << endl;
}

sum = (FourbyFour[0][0] + FourbyFour[1][1] + FourbyFour[2][2] + FourbyFour[3][3]);

cout << endl;
cout << "Diagonally, the sum of the numbers is  " << sum << "." << endl;
cout << endl;

return 0;
}

Tuesday, October 28, 2014

Drivers licence exam C++

/////////////////////////////////////////////////////////////////////////////////////////////////
// Author:Joe Student                                               //
//                                                                                                      //
// Date:                    09/06/14    34                                                  //
// Program Description:Write a program that grades the written   //
//portion of the driver's license exam.                                            //
//                                                                                                     //
// Input:  Answers (A,B,C,D)                                                        //
// Processing:   Compared to prepared answer bank                     //
// Output: Number wrong, number right , pass/fail                       //
///////////////////////////////////////////////////////////////////////////////////////////////

#include <iostream>
#include <cctype>
using namespace std;
void checkAnswers(char[], char[], int, int);
int main() {
    const int NUM_QUESTIONS = 20;
    const int MIN_CORRECT = 15;
    char answers[NUM_QUESTIONS] = {'B', 'D', 'A', 'A', 'C','A', 'B', 'A', 'C', 'D','B', 'C', 'D', 'A', 'D','C', 'C', 'B', 'D','A'};
    char stu_answers[NUM_QUESTIONS];
    //Loop for users answers
    for (int replies = 0; replies < NUM_QUESTIONS; replies++) {
        cout<< "Please enter your answers (Hint: Use capital letters): "
            << (replies + 1) << ": ";
        cin >> stu_answers[replies];
        //Validation of users answers
        while (stu_answers[replies] != 'A' && stu_answers[replies] != 'B' && stu_answers[replies] != 'C' && stu_answers[replies] != 'D') {
            cout << "You must enter A, B, C, or D\n";
            cout<< "Please enter your answers (Hint: Use capital letters): "
                << (replies + 1) << ": ";
            cin >> stu_answers[replies];
        }
    }
    checkAnswers(answers, stu_answers, NUM_QUESTIONS, MIN_CORRECT);
    return 0;
}
void checkAnswers(char answers1[], char stu_answers1[], int NUM_QUESTIONS, int MIN_CORRECT) {
    //cout << "max: " << NUM_QUESTIONS;
    int correctAnswers = 0;
    //Check the student's replies against the correct answers
    for (int i = 0; i < NUM_QUESTIONS; i++)  {
        if (answers1[i] == stu_answers1[i])
            correctAnswers++;
    }
    //Did they pass or fail?
    cout << "\n\n\n\n\n\n\n\n\nYou must have at least 15 correct to pass.";
    cout << "\n-------------------------------------------";

    if (correctAnswers >= MIN_CORRECT) {
        cout << "\nStudent passed the exam";
       cout << "\n---------------------------\n\n\n\n\n";

    }
    else {
        cout <<"\nStudent failed the exam";
       cout << "\n---------------------------\n\n\n\n\n";

    }
    //Display a list of the questions that were incorrectly answered.
    cout << "The list below shows the question numbers of the incorrectly";
    cout << " answered questions.\n";
    for (int i = 0; i < NUM_QUESTIONS; i++)  {
        if (answers1[i] != stu_answers1[i])
            cout << "Question # " << i << " is incorrect." << endl;
    }
    //Display the number of correct and incorrect answers provided by the student.
    cout << "\nCorrect Answers = " << correctAnswers << endl;
    cout << "Incorrect Answers = " << NUM_QUESTIONS - correctAnswers << endl;
}

Monday, October 13, 2014

Simple Write your name in ASCII C++



///////////////////////////////////////////////////////////////////
// Author:Zachary //
//                                                               //
// Date: 08/21/2014                                              //
// Program Description: Write a C++ program using output         //
//statements (cout) to print the first three letters of your     //
//first name in big blocks. This program does not read anything  //
//from the keyboard.                                             //
//Each letter is formed using 7 rows and 5 columns using the     //
//letter itself.                                                 //
//                                                               //
// Input:                                                        //
// Processing:                                                   //
// Output:                                                       //
///////////////////////////////////////////////////////////////////
#include <iostream>

using namespace std;

int main()
{
    cout << "ZZZZZ  DDDDD SSSSS" << endl;
    cout << "    Z  D   D S    " << endl;
    cout << "   Z   D   D S    " << endl;
    cout << "  Z    D   D SSSSS" << endl;
    cout << " Z     D   D     S" << endl;
    cout << "Z      D   D     S" << endl;
    cout << "ZZZZZ  DDDDD SSSSS" << endl;
    return 0;
}

Internet Service Provider C++

/*
 * isp.cpp
 *
 *  Created on: Sep 24, 2014
 *      Author: Zach
 */

#include "isp.h"
#include <iostream>
using namespace std;

int main ()
{
int choice;
int hours;
double total;

double A = 9.95;
double B = 14.95;
double C = 19.95;
double D = 2.00;
double E = 1.00;

//Display
cout << " \t\What is your package subscription \n";
cout << "1. A.$9.95 per month. 10 hours access. Additional Hours are $2.00\n";
cout << "2. B.$14.95 per month. 20 hours access. Additional hours are $1.00\n";
cout << "3. C.$19.95 per month. Unlimited access.\n";
cout << "Enter your choice: ";
cin >> choice;

if (choice >=1 && choice <=3)
{
cout << "How many hours were used?  ";
cin >> hours;
switch (choice)
{
case 1:
{
total = A + (hours - 10)*D;
break;
}
case 2:
{
total = B + (hours - 20)*E;
break;
}
case 3:
{
total = C;
break;
}

default:
cout<<"You enter a wrong value!"<<endl;
cout << "The valid choices are 1 through 3. \n Run the program again.";
}

cout << "Your charge for this month is: $ "<<total<<endl;
}
else if (choice !=3)
{
cout << "The valid choices are 1 through 3. \n Run the program again.";
}
return 0;
}

Celsius to Fahrenheit converter C++

//============================================================================
// Name        : f2c.cpp
// Author      : Zachary S
// Version     :X^e2
// Copyright   : my granny will find you
// Description : Using a loop that counts to 20, it takes in the loop number, converts it as a temp in F and prints it out as a C
//============================================================================
#include <iostream>
 using namespace std;
 double toCelcius(int Temp)
 {
     return (5.0/9.0)*((double)Temp - 32.0);
 }
 int main()
 {
     cout << "fahrenheit \t to \t  celsius\n";
     for (int i = 0;i <= 20;i++)
     {
         cout << i << "\t\t" << (int)toCelcius(i) << endl;
     }
 }

Simple Miles per gallon calculator C++

/*
// Author:Zachary //
//                                                               //
// Date:                    09/06/14 1:34                        //
// Program Description:Write a program that asks the user for    //
 *  how many miles they drove and how much gas they used         //
//                                                               //
// Input:  distance, gallons                             //
// Processing:   MPG = MilesDriven / GallonsUsed                 //
// Output: MPG                                                   //

 */

#include <iostream>

using namespace std;

/*
 *
 */

int main()
{
   
   int gallons = 0;      
   double distance = 0.0;    
   double mpg = 0.0;
   do
   {
      cout << "Please input how many gallons of gasoline are in your vehicle: ";
      cin >> gallons;
      cout << "Please input the distance in miles you traveled in your vehicle: ";
      cin >> distance;
      mpg = distance / gallons;
       cout << "Your vehicle's MPG is: " << mpg << endl;
    }while(gallons >-1);
 
    return 0;
}

Thursday, July 17, 2014

Top Ten Gamers Java

Class 1: Gamer List 

public class GamerList
{

    private class Node
    {
        String name;
        int score;
        Node next;

        Node(String Score1, int Score2)
        {
            name = Score1;
            score = Score2;
        }
    }
    private Node head;

    public GamerList()
    {
        head = null;
    }

    public boolean isEmpty()
    {
        return head == null;
    }

    public int size()
    {
        int count = 0;
        Node p = head;
        while(p != null)
        {
            count++;
            p = p.next;
        }
        return count;
    }

    public void insert(String name, int score)
    {
        Node node = new Node(name, score);

        if(isEmpty())
        {
            head = node;
            node.next = null;
        }
        else
        {
            Node curr = head;
            Node prev = null;
            while(curr != null && curr.score > node.score)
            {
                 prev = curr;
                 curr = curr.next;
            }
            if(prev == null)
            {
                head = node;
                node.next = curr;
            }
            else
            {
                prev.next = node;
                node.next = curr;
            }
        }

        if(size() > 10)
        {
            Node currentPtr = head;
            for (int i = 0; i < 9; i++) {
                currentPtr = currentPtr.next;
            }
            currentPtr.next = null;
        }
    }

    public void printList() {
        Node temp = head;
        while(temp != null) {
            System.out.print(temp.name + " " + temp.score + " ");
            System.out.println("");
            temp = temp.next;
        }
    }
}

Class 2: Player List 

public class PlayerList {
public static void main(String[] args) {


   GamerList list1 = new GamerList();

   list1.insert("RED", 10);
   list1.insert("ASS", 30);
   list1.insert("PCP", 20);
   list1.insert("ZDS", 50);
   list1.insert("ZZZ", 60);
   list1.insert("AAA", 40);
   list1.insert("BBB",80);
   list1.insert("CCC", 70);
   list1.insert("REJ", 90);
   list1.insert("SER", 100);
   list1.insert("AZZ", 5);
   list1.insert("JJJ", 15);
   System.out.println ("GALAXIA");
   System.out.println("HIGH SCORES" + " : ");
   list1.printList();
}
}

Ship Simulator Java

Class 1 : Cargo Ship 
package ship;

public class Cargo_Ship extends ship {
public int CargoCapacity;
public Cargo_Ship()
{
CargoCapacity = 0;
}
public Cargo_Ship (int cc, String n, String y)
{
super(n,y);
CargoCapacity = cc;
}
public int getCargoCapacity() {
return CargoCapacity;
}
public void setCargoCapacity(int cargoCapacity) {
this.CargoCapacity = cargoCapacity;
}
public String toString(){
return "The ship's name is: " + getShipName() +
" and the ship's cargo capacity is: " + getCargoCapacity()
+ " and the ship's year is: " + getShipYear();
}


}

Class 2: Cruise Ship 
package ship;

public class Cruise_Ship extends ship {
public int maxPasangers;
public Cruise_Ship()
{
maxPasangers = 0;
}
public Cruise_Ship (int mp, String n, String y)
{
super(n,y);
maxPasangers = mp;
}
public int getMaxPasangers() {
return maxPasangers;
}
public void setMaxPasangers(int maxPasangers) {
this.maxPasangers = maxPasangers;
}
public String toString(){
return "The ship's name is: " + getShipName() + " and the ship's max pasangers is: " + getMaxPasangers() + " and the ship's year is: " + getShipYear();
}


}

Class 3: Ship 
package ship;

public class ship {
public String shipName;
public String shipYear;
 public ship()
{
shipName = "";
shipYear = "";
}
 public ship (String n, String y)
{
 shipName = n;
 shipYear = y;
}
public String getShipName() {
return shipName;
}
public void setShipName(String shipName) {
this.shipName = shipName;
}
public String getShipYear() {
return shipYear;
}
public void setShipYear(String shipYear) {
this.shipYear = shipYear;
}
public String toString(){
return "The ship's name is: " + getShipName() + " and the ship's year is: " + getShipYear();
}


}

Class 4: Ship Demo
package ship;

import java.util.ArrayList;
public class Ship_Demo extends ship {
public static void main(String[] args)
{
ArrayList<ship> list = new ArrayList<ship>();
ship ship1 = new ship();
ship ship2 = new ship();
ship1.setShipName("DAVISON");
ship2.setShipName("DENEBOLA");
ship1.setShipYear("1982");
ship2.setShipYear("1762");
list.add(ship1);
list.add(ship2);
for (ship entry : list) {
System.out.printf("Name = %s\tYear = %s\n",
entry.getShipName(), entry.getShipYear());
}
}
}


Sales Simulator Java

Class 1 : 
Customer 

package Orders_package;

public class Customer
{


}


Class 2: 
CustomerSales 
package Orders_package;

public class CustomerSales
{
public static int numberOfOrders = 0;
public static double ordersTotal = 0.0;
private int orderNumber;
private String company;
private static double totalOrder;

public CustomerSales()
{
orderNumber = 0;
company = " ";
totalOrder = 0.0;
numberOfOrders++;
}
public CustomerSales(int x, String y, double z)
{
orderNumber = x;
company = y;
totalOrder = z;
numberOfOrders++;
ordersTotal += totalOrder;
}
public CustomerSales(int x)
{
Orders();
this.orderNumber = x;
numberOfOrders++;
}
public setCompany =new company (String)
{
company = c;
}
private void Orders() {
// TODO Auto-generated method stub

}
public void setTotalOrder(double x)
{
totalOrder += x;
ordersTotal += totalOrder;
}
public void setOrderNumber(int ord)
{
orderNumber = ord;
}
public static void incrementNumberOfOrders()
{
Orders.numberOfOrders++;
}
public static void incrementTotalOrders(double x)
{
Orders.ordersTotal += x;
totalOrder += x;
}
public static void main(String[ ] args)
{
Orders ord1 = new Orders();
Orders ord2 = new Orders(123, "ABC", 324.50);
Orders ord3 = new Orders(456);
Orders ord4;
Orders ord5 = new Orders();
ord3.setCompany("DEF");
ord3.setTotalOrder(798.75);
ord1.setTotalOrder(493.25);
ord4 = ord2;
}


}


Class 3: 
Orders 

package Orders_package;

public class Orders
{
public static int numberOfOrders = 0;
public static double ordersTotal = 0.0;
private int orderNumber;
private String company;
private double totalOrder;

public Orders()
{
orderNumber = 0;
company = " ";
totalOrder = 0.0;
numberOfOrders++;
}
public Orders(int x, String y, double z)
{
orderNumber = x;
company = y;
totalOrder = z;
numberOfOrders++;
ordersTotal += totalOrder;
}
public Orders(int x)
{
orders();
this.orderNumber = x;
numberOfOrders++;
}
private void orders()
{
// TODO Auto-generated method stub

}
public void setCompany(String c)
{
company = c;
}
public void setTotalOrder(double x)
{
totalOrder += x;
ordersTotal += totalOrder;
}
public void setOrderNumber(int ord)
{
orderNumber = ord;
}
public static void incrementNumberOfOrders()
{
Orders.numberOfOrders++;
}
public static void incrementTotalOrders(double x)
{
Orders.ordersTotal += x;
double TotalOrder = x;
}
public static void main(String[ ] args)
{
Orders ord1 = new Orders();
Orders ord2 = new Orders(123, "ABC", 424.50);
Orders ord3 = new Orders(456);
Orders ord4;
ord3.setCompany("DEF");
ord3.setTotalOrder(898.75);
ord1.setTotalOrder(593.25);
ord4 = ord2;
}

}

Recursive Java

package Recursive_lab;

import java.util.Scanner;
public class Power
{
    public static void main(String[] args)
    {
        int base;
        int exp;
        int answer;
        Scanner scan = new Scanner(System.in);
        System.out.print("Base number ");
        base = scan.nextInt();
        System.out.print("Raised to the power of? ");
        exp = scan.nextInt();
        answer = pow (base,exp);
        System.out.println(base + " raised to the power of " + exp + " is " + answer);
    }

    public static int pow(int base, int exp)
    {
        int pow;
        if (exp == 0)
            return 1;
        return base * pow(base, exp-1);
}
}

Parity Bit Java

/////////////////////////////////////////////////////////////////////////
// YOUR NAME HERE                                          //
//                                                                              //
//                                                                              //
//takes random 2d array and determines a parity bit//
//                                                               //
//////////////////////////////////////////////////////////////////////////
package lab;

import java.util.Random;

public class LabFirst1
{
public static void main(String[] args)
{
//setting up array
final int rowWidth = 8;
final int colHeight = 4;
   int total = 0;


   Random rand = new Random();

int [][] board = new int [colHeight][rowWidth];

  for (int row = 0; row < board.length; row++)
  {
for (int col = 0; col < board[row].length; col++)
{
board[row][col] = rand.nextInt(2);
}

//setting up array and Parity bit
}
System.out.println( "Data     \t Parity bit");
for(int i = 0; i < board.length; i++)
{
for(int j = 0; j < board[i].length; j++)
{
System.out.print( board[i][j] + " " );
}
//setting up Parity Bit
{
total +=  board[i][colHeight];
// didn't remember the method you used in class
if (total == 1)
   total = 1;
else if (total == 3)
   total = 1;
else if (total == 5)
   total = 1;
else if (total == 8)
   total = 1;
else if (total == 6)
   total = 0;
else if (total == 2)
   total = 0;
else if (total == 4)
   total = 0;
else if (total == 6)
   total = 0;
else if (total == 7)
   total = 0;
}
System.out.print(" ");
System.out.println(total);
}

}
  }



Banking Account Simulator Java

UML:













Class 1 : 
Account Test 
****************************************************

*  Name: YOUR NAME HERE

*  Date: ++++++++++

*  Purpose:

* Input: {Checking inital deposits and (deposit/withdraw)}{ Savings inital deposits and (deposit/withdraw)}

*  Processing: running totals, counters, multiplication, division

*  Output: What results will be displayed to the user
*  -------------Monthly Transactions------------
Deposit transaction Number:   1 Amount 10.0
Withdrawl Transactoin Number: 1 Amount 23.0
Withdrawl Transactoin Number: 2 Amount 434.05
Deposit transaction Number:   2 Amount 650.0
Withdrawl Transactoin Number: 3 Amount 43.0
Withdrawl Transactoin Number: 4 Amount 80.0
Deposit transaction Number:   3 Amount 5.0
Withdrawl Transactoin Number: 5 Amount 20.0

End of the month:
-------------------
-------------------

Savings balance = $953.08
Checking balance = $164.95


****************************************************************/

package lastlab;
import java.text.*;

public class AccountTest
{
public static void main(String[] args)
{
System.out.println("-------------Monthly Transactions------------");
//change values here
SavingsAccount Savings =
new SavingsAccount(100);
CheckingAccount Checking =
new CheckingAccount(100);
Savings.deposit(434);
Savings.deposit(100);
Savings.transfer(Checking, 10);
Checking.withdraw(23);
Checking.withdraw(434.05);
Checking.deposit(650);
Savings.deposit(434.05);
Checking.withdraw(43);
Checking.withdraw(80);
Savings.transfer(Checking, 5);
Checking.withdraw(20);



//end of month reconsiling
Savings.addInterest();
Checking.deductFees();
        DecimalFormat df = new DecimalFormat("#.##");
//Display set up
System.out.println("");
System.out.println("End of the month:");
System.out.println("-------------------");
System.out.println("-------------------");
System.out.println("");
System.out.println("Savings balance = $" +df.format(Savings.getBalance()));
System.out.println("Checking balance = $" +df.format(Checking.getBalance()));
}
}


Class 2: 
Bank Account 
package lastlab;
public class BankAccount
{
public BankAccount()
{
balance = 0;
}
public BankAccount(double initialBalance)
{
balance = initialBalance;
}
public void deposit(double amount)
{
balance = balance + amount;
}
public void withdraw(double amount)
{
balance = balance - amount;
}
public double getBalance()
{
return balance;
}
public void transfer(BankAccount other, double amount)
{
withdraw(amount);
other.deposit(amount);
}
protected double balance;
}

Class 3:
Checking Account 
package lastlab;
public class CheckingAccount extends BankAccount
{
public CheckingAccount(int initialBalance)
{
super(initialBalance);
DtransactionCount = 0;
WtransactionCount = 0;
}
public void deposit(double amount)
{
DtransactionCount++;
System.out.println("Deposit transaction Number:   " +DtransactionCount +(" Amount " ) + amount );
super.deposit(amount);
}
public void withdraw(double amount)
{
WtransactionCount++;
System.out.println("Withdrawl Transactoin Number: " + WtransactionCount+ (" Amount ") + amount );
super.withdraw(amount);
}
public void transCount(double amount)
{
TtransactionCount=DtransactionCount+WtransactionCount;
System.out.println("Total Transactions: " + TtransactionCount);
}
public void deductFees()
{

if
(TtransactionCount <= 4)

{
double fees1 = (0);
super.withdraw(fees1);
}
else
{
double fees1 = (25);
super.withdraw(fees1);
}
}
private int DtransactionCount;
private int WtransactionCount;
private int TtransactionCount;
}

Class 4: 
Savings Account 
package lastlab;

public class SavingsAccount extends BankAccount
{
public SavingsAccount(double rate)
{
interestRate = .01;
}
public void addInterest()
{
double interest = getBalance()*interestRate/365;
deposit(interest);
}
private double interestRate;
}

Geometry Area Calculator Java

Class 1: Area Calc 
---------------------------------


public class areacalculator
{
    private double area;

    public double circleArea(double r)
    {
area = (r * r) * Math.PI ;
return area;
    }

    public double rectangleArea(double length, double width)
    {
area = length * width;
return area;
    }

    public double triangleArea(double base, double height)
    {
area = (base * height)/2;
return area;
    }
}

Class 2 Geometry 
---------------------
import java.util.Scanner;
public class geo
{
   
    public static void main(String[] args)
    {
int selection;
double area = 0;
areacalculator Calc = new areacalculator();
Scanner console = new Scanner(System.in);
System.out.println("Area Calculator");
System.out.println("1." + "\tWhat is the Area of a Circle?");
System.out.println("2." + "\tWhat is the Area of a Rectangle?");
System.out.println("3." + "\tWhat is the Area of a Triangle?");
System.out.println("4." +  "\tExit");

while (true)
{
     selection = console.nextInt();
     if (selection == 1) {
    System.out.println("Radius? ");
    double radius = console.nextDouble();
    area = Calc.circleArea(radius);
    System.out.println("The area is? "+ area );
     }
     else if (selection == 2)
     {
    System.out.print("Enter the length? ");
    double length = console.nextDouble();
    System.out.println("Enter the width? ");
    double width = console.nextDouble();
    area = Calc.rectangleArea(length, width);
    System.out.println("The area is? "+ area );
     }
     else if (selection == 3)
     {
    System.out.print("Enter the base? ");
    double base = console.nextDouble();
    System.out.println("Enter the height? ");
    double height = console.nextDouble();
    area = Calc.triangleArea(base, height);
    System.out.println("The area is? "+ area );
     }
   
     else if (selection == 4)
     {
    System.exit(0);
     }
     else
     {
    System.out.println(selection+" Were you born wrong? Try again.");
     }

}
    }
}

Java Car Simulator

Class 1: Car
-----------------------------------

public class Car
{
public static void main(String []args)
{
FuelGauge amountOfFuel = new FuelGauge(15);
Odometer currentMileage = new Odometer(0);
while (amountOfFuel.getAmountOfFuel() > 0)
{
currentMileage.incrementcurrentMileage();
if( currentMileage.getcurrentMileage() % 24 == 0 )
amountOfFuel.decrementFeul();
{
System.out.printf("Amount Of Fuel = %s\tCurrent Mileage = %s\n",
amountOfFuel.getAmountOfFuel(), currentMileage.getcurrentMileage());
}
}
}
}


Class 2 : Fuel Gauge
-------------------------------
public class FuelGauge
{   
private int amountOfFuel;

public FuelGauge(int gallons){
 amountOfFuel = gallons;
 }
public int getAmountOfFuel(){
return amountOfFuel;
}
public void incrementFeul(){
if (amountOfFuel < 15 )
amountOfFuel++;
}
public void decrementFeul(){
if (amountOfFuel > 0 )
amountOfFuel--;
}
}


Class 3: Odometer 
----------------------------
public class Odometer 
{
 private int currentMileage;
public Odometer(int gallons)
{
  currentMileage = gallons;
}
public int getcurrentMileage()
{
return currentMileage;
}
 public void incrementcurrentMileage()
 {
if (currentMileage < 1000 )
currentMileage++;
if (currentMileage == 1000 )
currentMileage=0;
  }
public void decrementcurrentMileage()
{
if (currentMileage > 45 )
   currentMileage--;
 }
public void incrementMileage()
{
}

}