Jump to content
Sign in to follow this  
Lord Nikon

ICT 9 computer class stuff + marks

Recommended Posts

Whatever, I have to do Java and half the class failed lol

 

(I got 100%)

:P Nice work, although I don't know exactly what you guys are making what was the biggest or hardest project you guys did?

Share this post


Link to post
Share on other sites

Still relatively easy stuff... reading 2 dimensional datafiles/arrays into memory, adding the rows and columns etc

Share this post


Link to post
Share on other sites

Heres some Java, all it does is display "I am leet" (No quote) on the screen and uses a variable.

 

public class filename
{
public static void main (String[] args)
{
final String WORD = "I am leet";
System.out.println(WORD);
}
}

 

Yay for java

Share this post


Link to post
Share on other sites

Well, you'll have to start the program somehow. If you add another line, thats just another line of code...

 

Heres a datafile reader.

 

import java.io.*;

public class M4W1_07
{
// Declare Global Constants
static final int MAX_NUM = 100;
static final int STRING_SIZE = 5;

// Declare Global Variables
static TextReader dataFile;
static int rowsUsed;
static String name[] = new String[MAX_NUM];
static int a[] = new int[MAX_NUM];
static int b[] = new int[MAX_NUM];
static int c[] = new int[MAX_NUM];
static int rowTotals[] = new int[MAX_NUM];
static int row = 0;
static int total_a = 0, total_b = 0, total_c = 0;

public static void main(String []args)
{
readData();
processData();
writeReport();
}

static void readData()
{
try
{
dataFile = new TextReader(new FileReader("m4w1_07.dat"));
}

catch (IOException errorMessage)
{
System.out.println(errorMessage);
System.exit(1);
}

String nameIn = "";

while (dataFile.eof() == false)
{
row = row + 1;
nameIn = "";
for (int c = 1; c <=STRING_SIZE; c++)
nameIn = nameIn + dataFile.getAnyChar();
name[row] = nameIn;
a[row] = dataFile.getInt();
b[row] = dataFile.getInt();
c[row] = dataFile.getlnInt();
}

rowsUsed = row;
dataFile.close();
}

static void processData()
{
for (int row = 1; row <= rowsUsed; row++)
rowTotals[row] = a[row] + b[row] + c[row];

for (int row = 1; row <= rowsUsed; row++)
{
total_a = total_a + a[row];
total_b = total_b + b[row];
total_c = total_c + c[row];
}


}

static void writeReport()
{
System.out.printf("%10s%5s%5s%7s\n\n", "A", "B", "C", "TOTAL");
for (int row = 1; row <= rowsUsed; row++)
System.out.printf("%5s%5d%5d%5d\n", name[row], a[row], b[row], c[row], rowTotals[row]);
System.out.println();
System.out.printf("%5s%5d%5d%5d\n\n", "TOTAL", total_a, total_b, total_c);
}
}

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...