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()
{
}

}