Monday, April 28, 2008

Linuxgym-Chap4

http://www.ibm.com/developerworks/aix/

Q2 : Character count piping
Experiment by using the command "cat | wc -m", typing a few lines, and then using ctrl-D to return to the command prompt. This outputs a single number indicating the number of characters you've typed. Unlike the previous question, no filename is printed.
Modifying this technique, store the number of characters of the file /usr/local/linuxgym-data/gutenberg/0ws0310.txt into a file called "pipecount.txt" with no other text, such as the filename.

A:
wc -m /usr/local/linuxgym-data/gutenberg/0ws0310.txt ---> count characters
echo [number of charater] > pipecount.txt
Q4:View the end of a file
Store the last 103 lines of the file "/usr/local/linuxgym-data/gutenberg/4mwsm10.txt" into the file "lastlines.txt". Note that this should include both non-empty and empty lines
A :

tail -n103 /usr/local/linuxgym-data/gutenberg/4mwsm10.txt > lastlines.txt

Q5:Append the output
Copy the file /usr/local/linuxgym-data/census/a-j_malenames.txt to a file called appendix.txt in your ch4-pipewild directory. Append to appendix.txt the contents of /usr/local/linuxgym-data/census/k-z_malenames.txt making no other modifications.

A:
cp usr/local/linuxgym-data/census/a-j_malenames.txt appendix.txt
cat /usr/local/linuxgym-data/census/k-z_malenames.txt >> appendix.txt

Q6:

Sunday, April 27, 2008

PF First Assigment

Part I
- UnifiedDomination
4.75 / 5 marks

UnifiedDomination has repeated code for reading the two players' names

Part II
- Task 1: total # of armies calculation
2.5 / 2.5 marks

- Task 2: accessor functions
2.5 / 2.5 marks

- Task 3: constructors
5 / 5 marks

- Task 4: Player.startTurn
2.5 / 2.5 marks

- Task 5: Player.placeArmy
3.25 / 3.75 marks

placeArmy() breaks encapsulation of the Territory class

- Task 6: Player.attack
3.75 / 3.75 marks



YOUR MARK

24.25/25

The world is flat

Time is truly money: shaving even five seconds off the processing time of an order is significant(P41)
The gains in productivity will be staggering for those countries, companies and individuals who can absorb the new technological tools.(P47)

Sunday, April 6, 2008

Reflec week 6

Mid-Exam
"Time flies" that 's true .
Oh man .You 're such a lazy guys
C'mon .Finish the programming soon and take a break.

Friday, April 4, 2008

Lab 6 PF

import java.util.*;

public class Concert
{ private final double TAX_RATE = 0.21;
private final int PARTNERS = 3;
private Guards guards = new Guards();
private Stadium stadium = new Stadium();
private double BAND = 10000.00;
private Shirts shirts;
public Concert()
{ stadium.sell();
shirts = new Shirts();
showOutput(); }

void showOutput()
{ System.out.println("Total attendance was " + stadium.attendance());
System.out.println("My take is $" + twoDecimals(myTake()));
System.out.println(); }

private double myTake()
{ return nett() / PARTNERS; }

private double tax(double amount)
{ return amount * TAX_RATE; }

private double nett()
{ double profit = profit() + shirts.profit();
return profit - tax(profit); }

private double profit()
{ return income() - cost(); }

private double income()
{ return stadium.income(); }

private double cost()
{ double cost = BAND + stadium.cost() + guards.cost(stadium.attendance()) ;
return cost; }

private double twoDecimals(double amount)
{ int intResult = (int) (amount * 100);
return intResult / 100.0; }
}
-----------------------------------------------------------------------------


public class Stadium
{ private final double RENT = 20000.00;
private final double SECURITY_RATE = 0.32;
private Guards guards;
private SeatGroup cheap, great;

public Stadium()
{ cheap = new SeatGroup("cheap", 2000, 60.00);
great = new SeatGroup("great", 100, 500.00); }

public void sell()
{ cheap.sell();
great.sell(); }

public int attendance()
{ return cheap.sold() + great.sold(); }

public double income()
{ return cheap.income() + great.income(); }

public double cost()
{ return RENT; }
}
--------------------------------------------
import java.util.*;
import java.util.Random;
public class SeatGroup
{ private Scanner input = new Scanner(System.in);
private Random random = new Random(121);
private String name;
private int number;
private double price;
private int sold;

public SeatGroup(String name, int number, double price)
{
this.name = name;
this.number = number;
this.price = price;
}

public int sold()
{
return sold;
}
public void sell()
{
sold = generateSold(); //You would also need to change the prompt below to something meaningful.

}


private int generateSold()
{
double value = random.nextDouble();
return (int) (value * number);
}



public double income()
{
return price * sold;
}
}

-------------------------------------------------------

public class Guards
{
private final int PER_GUARD = 200;
private final double RATE = 56.00;
private final int HOURS = 6;


public double cost(int attendance)
{
// Refer tutorial notes and lecture notes to calculate cost
return RATE * HOURS * guards(attendance);

}

private int guards(int attendance)
{
return roundUp(attendance / PER_GUARD);
}

private int roundUp(double value)
{
return (int) Math.ceil(value);
}
}
--------------------------------------------

import java.util.*;

public class Shirts

{
private final double costs =2;
private final double print =1;
private final double price =40;
private final double number =600;
private int sold;

private Scanner input = new Scanner(System.in);



public Shirts()
{
System.out.print("Number of shirts sold :" );
sold = input.nextInt();
}

public double profit()
{
return price * sold - costs();
}

private double costs()
{
return costs * print * number ;
}


}