Professional Documents
Culture Documents
//c,o,s,t,t
insertionSort(name);
int n = a.length;
System.out.println(a);
}
}
import java.util.Scanner;
}
package midtermactivities;
/* 1,2,3
* 4,5,6
* 7,8,9
*/
public class TwoDimensionalDemo1 {
public static void main(String[] args) {
/*int [][] matrix = {
{1,2,3},
{4,5,6},
{7,8,9}
};*/
int [][] matrix = new int[3][3];
matrix[0][0]= 1;
matrix[0][1]= 2;
matrix[0][2]= 3;
matrix[1][0]= 4;
matrix[1][1]= 5;
matrix[1][2]= 6;
matrix[2][0]= 7;
matrix[2][1]= 8;
matrix[2][2]= 9;
}
}
}
package prelimactivities;
import java.util.Scanner;
//1,2,3
public class ArrayDemo {
}
package midtermactivities;
import java.util.Scanner;
/* 11,12,13,14,15
*
*/
public class ArrayDemo1 {
}
package prelimactivities;
import java.util.Arrays;
import java.util.Random;
https://beginnersbook.com/2014/07/java-program-for-bubble-sort-in-ascending-descending-order/
2windows
import java.util.Scanner;
//Declare attributes
private String name;
private int studNumber;
private double grade;
//Create constructor
public Student() {
this.name="";
this.studNumber=0;
this.grade=0.0;
}
//constructor with fields
public Student(String name, int studNumber, double grade) {
super();
this.name = name;
this.studNumber = studNumber;
this.grade = grade;
}
//create standard methods
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getStudNumber() {
return studNumber;
}
public void setStudNumber(int studNumber) {
this.studNumber = studNumber;
}
public double getGrade() {
return grade;
}
public void setGrade(double grade) {
this.grade = grade;
}
}
public class Grade {
//attributes
private double assignment = 0.0;
private double attendance = 0.0;
private double machineProblem = 0.0;
private double project = 0.0;
//default constructor
public Grade() {
//customized methods
public double computeGrade(double assignment, double attendance, double machineProblem,
double project){
double grade = 0.0;
grade = (assignment + attendance+ machineProblem + project)/4;
return grade;
}
System.out.println(prelimAverageValue);
}
public class ComputeGradeTester3 {
System.out.println(prelim[i].computeGrade(prelim[i].getAssignment(),
prelim[i].getAttendance(), prelim[i].getMachineProblem(), prelim[i].getProject()));
}
MIDTERM CODES
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class CopyBytes {
FileInputStream in = null;
FileOutputStream out = null;
try {
in = new FileInputStream("txtFileDemo/demoIn.txt");
out = new FileOutputStream("txtFileDemo/demoOut.txt");
int c;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
try {
inputStream = new FileReader("txtFileDemo/demoIn.txt");
outputStream = new FileWriter("txtFileDemo/demoOut.txt");
char c;
while((c = (char)inputStream.read())!=(char)-1) {
outputStream.write(c);
System.out.print(c);
}
} finally {
if(inputStream!=null) {
inputStream.close();
}
if(outputStream!=null) {
outputStream.close();
}
}
}
import java.io.Console;
import java.util.Arrays;
import java.io.IOException;
Console c = System.console();
if (c == null) {
System.err.println("No console.");
System.exit(1);
}
if (verify(login, oldPassword)) {
boolean noMatch;
do {
char [] newPassword1 = c.readPassword("Enter your new password: ");
char [] newPassword2 = c.readPassword("Enter new password again: ");
noMatch = ! Arrays.equals(newPassword1, newPassword2);
if (noMatch) {
c.format("Passwords don't match. Try again.%n");
} else {
change(login, newPassword1);
c.format("Password for %s changed.%n", login);
}
Arrays.fill(newPassword1, ' ');
Arrays.fill(newPassword2, ' ');
} while (noMatch);
}
try {
FileReader fr = new FileReader("txFileDemo/names.txt");
LineNumberReader lnr = new LineNumberReader(fr);
//lnr.setLineNumber(1);
lnr.close();
} catch (Exception e) {
e.printStackTrace();
}
System.exit(0);
}
}