public class Banner{
private String word;
private char font;
public Banner(String word, char font){
this.word = word;
this.font = font;
}
public void display(){
String B1 = " ##### ";
String B2 = " # # ";
String B3 = " ##### ";
String B4 = " # # ";
String B5 = " ##### ";
String [] B = {B1,B2,B3,B4,B5};
String L1 = " # ";
String L2 = " # ";
String L3 = " # ";
String L4 = " # ";
String L5 = " ##### ";
String [] L = {L1,L2,L3,L4,L5};
String U1 = " # # ";
String U2 = " # # ";
String U3 = " # # ";
String U4 = " # # ";
String U5 = " #### ";
String [] U = {U1,U2,U3,U4,U5};
String E1 = " ###### ";
String E2 = " # ";
String E3 = " ###### ";
String E4 = " # ";
String E5 = " ###### ";
String [] E = {E1,E2,E3,E4,E5};
int iw = 0;
B = apply_font(B,'#',this.font);
L = apply_font(L,'#',this.font);
U = apply_font(U,'#',this.font);
E = apply_font(E,'#',this.font);
while(iw < 5){
int ia = 0 ;
while(ia < this.word.length()){
if(word.charAt(ia) == 'B'){
System.out.print(B[iw]);
}else if(word.charAt(ia) == 'L'){
System.out.print(L[iw]);
}else if(word.charAt(ia) == 'U'){
System.out.print(U[iw]);
}else if(word.charAt(ia) == 'E'){
System.out.print(E[iw]);
}ia = ia + 1;
}System.out.println();
iw = iw + 1;
}
}
public String[] apply_font(String [] w,char f,char r){
int i = 0;
String[] font = new String[w.length]; //String that has length as w
while(i < w.length){
int j = 0;
font[i]="";
while(j < w[i].length()){
if (w[i].charAt(j) == f){
font[i] = font[i] + r;
}else{
font[i] = font[i] + ' ';
}j += 1;
}
i += 1;
}
return font;
}
public static void main(String[] args){
String word = "BLUE";
Banner B = new Banner(word,'+');
B.display();
}
}
แสดงบทความที่มีป้ายกำกับ Lab 8 แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ Lab 8 แสดงบทความทั้งหมด
วันอาทิตย์ที่ 8 พฤศจิกายน พ.ศ. 2558
วันจันทร์ที่ 2 พฤศจิกายน พ.ศ. 2558
Display student records, sorted by age, use insertion sort.
public class Student{
private String name;
private int ID;
private int age;
private int weight;
private int height;
public Student(String name, int ID,int age,int weight,int height){
this.name = name;
this.ID = ID;
this.age = age;
this.weight = weight;
this.height = height;
}
public String get_name(){
return this.name;
}
public int get_ID(){
return this.ID;
}
public int get_age(){
return this.age;
}
public int get_weight(){
return this.weight;
}
public int get_height(){
return this.height;
}
public void set_name(String name){
this.name = name;
}
public void set_ID(int ID){
this.ID = ID;
}
public void set_age(int age){
this.age = age;
}
public void set_weight(int weight){
this.weight = weight;
}
public void set_height(int height){
this.height = height;
}
public void display(){
System.out.println("Name: " +this.name);
System.out.println("ID: " +this.ID);
System.out.println("Age: " +this.age);
System.out.println("Weight: " +this.weight);
System.out.println("Height: " +this.height);
System.out.println();
}
public static void main(String[] args){
Student a = new Student("Gun" , 32075, 26, 80, 174);
Student b = new Student("Rit" , 32078, 25, 70, 170);
Student c = new Student("Frame" , 32080, 19, 58, 173);
Student d = new Student("Coffee" , 32057, 18, 50, 168);
Student e = new Student("Boat" , 32087, 16, 60, 165);
Student [] data = {a,b,c,d,e};
sort(data);
a.display();
b.display();
c.display();
d.display();
e.display();
}
public static void sort(Student [] data){
int i = 1;
while(i < data.length){
int value_a = data[i].get_age();
String value_n = data[i].get_name();
int value_I = data[i].get_ID();
int value_w = data[i].get_weight();
int value_h = data[i].get_height();
int j = i;
while(j > 0 && data[j-1].get_age() > value_a){
data[j].set_age(data[j-1].get_age());
data[j].set_name(data[j-1].get_name());
data[j].set_ID(data[j-1].get_ID());
data[j].set_weight(data[j-1].get_weight());
data[j].set_height(data[j-1].get_height());
j = j - 1;
}
data[j].set_age(value_a);
data[j].set_name(value_n);
data[j].set_ID(value_I);
data[j].set_weight(value_w);
data[j].set_height(value_h);
i = i + 1;
}
}
}
private String name;
private int ID;
private int age;
private int weight;
private int height;
public Student(String name, int ID,int age,int weight,int height){
this.name = name;
this.ID = ID;
this.age = age;
this.weight = weight;
this.height = height;
}
public String get_name(){
return this.name;
}
public int get_ID(){
return this.ID;
}
public int get_age(){
return this.age;
}
public int get_weight(){
return this.weight;
}
public int get_height(){
return this.height;
}
public void set_name(String name){
this.name = name;
}
public void set_ID(int ID){
this.ID = ID;
}
public void set_age(int age){
this.age = age;
}
public void set_weight(int weight){
this.weight = weight;
}
public void set_height(int height){
this.height = height;
}
public void display(){
System.out.println("Name: " +this.name);
System.out.println("ID: " +this.ID);
System.out.println("Age: " +this.age);
System.out.println("Weight: " +this.weight);
System.out.println("Height: " +this.height);
System.out.println();
}
public static void main(String[] args){
Student a = new Student("Gun" , 32075, 26, 80, 174);
Student b = new Student("Rit" , 32078, 25, 70, 170);
Student c = new Student("Frame" , 32080, 19, 58, 173);
Student d = new Student("Coffee" , 32057, 18, 50, 168);
Student e = new Student("Boat" , 32087, 16, 60, 165);
Student [] data = {a,b,c,d,e};
sort(data);
a.display();
b.display();
c.display();
d.display();
e.display();
}
public static void sort(Student [] data){
int i = 1;
while(i < data.length){
int value_a = data[i].get_age();
String value_n = data[i].get_name();
int value_I = data[i].get_ID();
int value_w = data[i].get_weight();
int value_h = data[i].get_height();
int j = i;
while(j > 0 && data[j-1].get_age() > value_a){
data[j].set_age(data[j-1].get_age());
data[j].set_name(data[j-1].get_name());
data[j].set_ID(data[j-1].get_ID());
data[j].set_weight(data[j-1].get_weight());
data[j].set_height(data[j-1].get_height());
j = j - 1;
}
data[j].set_age(value_a);
data[j].set_name(value_n);
data[j].set_ID(value_I);
data[j].set_weight(value_w);
data[j].set_height(value_h);
i = i + 1;
}
}
}
Find/count number of students with weight < 50.
public class Student{
private String name;
private int ID;
private int age;
private int weight;
private int height;
public Student(String name, int ID,int age,int weight,int height){
this.name = name;
this.ID = ID;
this.age = age;
this.weight = weight;
this.height = height;
}
public String get_name(){
return this.name;
}
public int get_ID(){
return this.ID;
}
public int get_age(){
return this.age;
}
public int get_weight(){
return this.weight;
}
public int get_height(){
return this.height;
}
public static void main(String[] args){
Student a = new Student("Gun" , 32075, 26, 80, 174);
Student b = new Student("Rit" , 32078, 25, 70, 170);
Student c = new Student("Frame" , 32080, 19, 58, 173);
Student d = new Student("Coffee" , 32057, 18, 50, 168);
Student e = new Student("Boat" , 32087, 16, 60, 165);
Student [] data = {a,b,c,d,e};
find(data);
}
public static void find(Student [] data){
int i = 0;
int count = 0;
while(i < data.length){
if(data[i].get_weight() < 50){
count = count + 1;
}
i = i + 1;
}
System.out.println("Have " + count + " students");
}
}
private String name;
private int ID;
private int age;
private int weight;
private int height;
public Student(String name, int ID,int age,int weight,int height){
this.name = name;
this.ID = ID;
this.age = age;
this.weight = weight;
this.height = height;
}
public String get_name(){
return this.name;
}
public int get_ID(){
return this.ID;
}
public int get_age(){
return this.age;
}
public int get_weight(){
return this.weight;
}
public int get_height(){
return this.height;
}
public static void main(String[] args){
Student a = new Student("Gun" , 32075, 26, 80, 174);
Student b = new Student("Rit" , 32078, 25, 70, 170);
Student c = new Student("Frame" , 32080, 19, 58, 173);
Student d = new Student("Coffee" , 32057, 18, 50, 168);
Student e = new Student("Boat" , 32087, 16, 60, 165);
Student [] data = {a,b,c,d,e};
find(data);
}
public static void find(Student [] data){
int i = 0;
int count = 0;
while(i < data.length){
if(data[i].get_weight() < 50){
count = count + 1;
}
i = i + 1;
}
System.out.println("Have " + count + " students");
}
}
Find minimum weight of students.
public class Student{
private String name;
private int ID;
private int age;
private int weight;
private int height;
public Student(String name, int ID,int age,int weight,int height){
this.name = name;
this.ID = ID;
this.age = age;
this.weight = weight;
this.height = height;
}
public String get_name(){
return this.name;
}
public int get_ID(){
return this.ID;
}
public int get_age(){
return this.age;
}
public int get_weight(){
return this.weight;
}
public int get_height(){
return this.height;
}
public static void main(String[] args){
Student a = new Student("Gun" , 32075, 26, 80, 174);
Student b = new Student("Rit" , 32078, 25, 70, 170);
Student c = new Student("Frame" , 32080, 19, 58, 173);
Student d = new Student("Coffee" , 32057, 18, 50, 168);
Student e = new Student("Boat" , 32087, 16, 60, 165);
Student [] data = {a,b,c,d,e};
find(data);
}
public static void find(Student [] data){
int i = 0;
int min = data[i].get_weight();
int index = 0;
while(i < data.length){
if(min > data[i].get_weight()){
min = data[i].get_weight();
index = i;
}
i = i + 1;
}
System.out.println("Min is " + data[index].get_name() + " weight = " + min);
}
}
private String name;
private int ID;
private int age;
private int weight;
private int height;
public Student(String name, int ID,int age,int weight,int height){
this.name = name;
this.ID = ID;
this.age = age;
this.weight = weight;
this.height = height;
}
public String get_name(){
return this.name;
}
public int get_ID(){
return this.ID;
}
public int get_age(){
return this.age;
}
public int get_weight(){
return this.weight;
}
public int get_height(){
return this.height;
}
public static void main(String[] args){
Student a = new Student("Gun" , 32075, 26, 80, 174);
Student b = new Student("Rit" , 32078, 25, 70, 170);
Student c = new Student("Frame" , 32080, 19, 58, 173);
Student d = new Student("Coffee" , 32057, 18, 50, 168);
Student e = new Student("Boat" , 32087, 16, 60, 165);
Student [] data = {a,b,c,d,e};
find(data);
}
public static void find(Student [] data){
int i = 0;
int min = data[i].get_weight();
int index = 0;
while(i < data.length){
if(min > data[i].get_weight()){
min = data[i].get_weight();
index = i;
}
i = i + 1;
}
System.out.println("Min is " + data[index].get_name() + " weight = " + min);
}
}
Find/count number of students with age < 30.
public class Student{
private String name;
private int ID;
private int age;
private int weight;
private int height;
public Student(String name, int ID,int age,int weight,int height){
this.name = name;
this.ID = ID;
this.age = age;
this.weight = weight;
this.height = height;
}
public String get_name(){
return this.name;
}
public int get_ID(){
return this.ID;
}
public int get_age(){
return this.age;
}
public int get_weight(){
return this.weight;
}
public int get_height(){
return this.height;
}
public static void main(String[] args){
Student a = new Student("Gun" , 32075, 26, 80, 174);
Student b = new Student("Rit" , 32078, 25, 70, 170);
Student c = new Student("Frame" , 32080, 19, 58, 173);
Student d = new Student("Coffee" , 32057, 18, 50, 168);
Student e = new Student("Boat" , 32087, 16, 60, 165);
Student [] data = {a,b,c,d,e};
count(data);
}
public static void count(Student [] data){
int i = 0;
int count = 0;
while(i < data.length){
if(data[i].get_age() < 30){
count = count + 1;
}
i = i + 1;
}
System.out.println("Have " + count + " students");
}
}
private String name;
private int ID;
private int age;
private int weight;
private int height;
public Student(String name, int ID,int age,int weight,int height){
this.name = name;
this.ID = ID;
this.age = age;
this.weight = weight;
this.height = height;
}
public String get_name(){
return this.name;
}
public int get_ID(){
return this.ID;
}
public int get_age(){
return this.age;
}
public int get_weight(){
return this.weight;
}
public int get_height(){
return this.height;
}
public static void main(String[] args){
Student a = new Student("Gun" , 32075, 26, 80, 174);
Student b = new Student("Rit" , 32078, 25, 70, 170);
Student c = new Student("Frame" , 32080, 19, 58, 173);
Student d = new Student("Coffee" , 32057, 18, 50, 168);
Student e = new Student("Boat" , 32087, 16, 60, 165);
Student [] data = {a,b,c,d,e};
count(data);
}
public static void count(Student [] data){
int i = 0;
int count = 0;
while(i < data.length){
if(data[i].get_age() < 30){
count = count + 1;
}
i = i + 1;
}
System.out.println("Have " + count + " students");
}
}
Find average age of students.
public class Student{
private String name;
private int ID;
private int age;
private int weight;
private int height;
public Student(String name, int ID,int age,int weight,int height){
this.name = name;
this.ID = ID;
this.age = age;
this.weight = weight;
this.height = height;
}
public String get_name(){
return this.name;
}
public int get_ID(){
return this.ID;
}
public int get_age(){
return this.age;
}
public int get_weight(){
return this.weight;
}
public int get_height(){
return this.height;
}
public static void main(String[] args){
Student a = new Student("Gun" , 32075, 26, 80, 174);
Student b = new Student("Rit" , 32078, 25, 70, 170);
Student c = new Student("Frame" , 32080, 19, 58, 173);
Student d = new Student("Coffee" , 32057, 18, 50, 168);
Student e = new Student("Boat" , 32087, 16, 60, 165);
Student [] data = {a,b,c,d,e};
average(data);
}
public static void average(Student [] data){
int i = 0;
int total = 0;
int n = 0;
float average = 0;
while(i < data.length){
total = total + data[i].get_age();
n = n + 1;
average = total/n;
i += 1 ;
}
System.out.println("average age = " + average);
}
}
private String name;
private int ID;
private int age;
private int weight;
private int height;
public Student(String name, int ID,int age,int weight,int height){
this.name = name;
this.ID = ID;
this.age = age;
this.weight = weight;
this.height = height;
}
public String get_name(){
return this.name;
}
public int get_ID(){
return this.ID;
}
public int get_age(){
return this.age;
}
public int get_weight(){
return this.weight;
}
public int get_height(){
return this.height;
}
public static void main(String[] args){
Student a = new Student("Gun" , 32075, 26, 80, 174);
Student b = new Student("Rit" , 32078, 25, 70, 170);
Student c = new Student("Frame" , 32080, 19, 58, 173);
Student d = new Student("Coffee" , 32057, 18, 50, 168);
Student e = new Student("Boat" , 32087, 16, 60, 165);
Student [] data = {a,b,c,d,e};
average(data);
}
public static void average(Student [] data){
int i = 0;
int total = 0;
int n = 0;
float average = 0;
while(i < data.length){
total = total + data[i].get_age();
n = n + 1;
average = total/n;
i += 1 ;
}
System.out.println("average age = " + average);
}
}
Find/count&display number of students with BMI > 25.
public class Student{
private String name;
private int ID;
private int age;
private int weight;
private int height;
public Student(String name, int ID,int age,int weight,int height){
this.name = name;
this.ID = ID;
this.age = age;
this.weight = weight;
this.height = height;
}
public String get_name(){
return this.name;
}
public int get_ID(){
return this.ID;
}
public int get_age(){
return this.age;
}
public int get_weight(){
return this.weight;
}
public int get_height(){
return this.height;
}
public static void main(String[] args){
Student a = new Student("Gun" , 32075, 26, 80, 174);
Student b = new Student("Rit" , 32078, 25, 70, 170);
Student c = new Student("Frame" , 32080, 19, 58, 173);
Student d = new Student("Coffee" , 32057, 18, 50, 168);
Student e = new Student("Boat" , 32087, 16, 60, 165);
Student [] data = {a,b,c,d,e};
BMI(data);
}
public static void BMI(Student [] data){
int i = 0;
float BMI = 0;
int count = 0;
while(i < data.length){
BMI = data[i].get_weight()*100*100/((data[i].get_height()*(data[i].get_height())));
if(BMI > 25){
System.out.println(data[i].get_name() +" BMI value = " +BMI);
count = count + 1;
}
i += 1 ;
}
System.out.println("Have" + count + "Students");
}
}
private String name;
private int ID;
private int age;
private int weight;
private int height;
public Student(String name, int ID,int age,int weight,int height){
this.name = name;
this.ID = ID;
this.age = age;
this.weight = weight;
this.height = height;
}
public String get_name(){
return this.name;
}
public int get_ID(){
return this.ID;
}
public int get_age(){
return this.age;
}
public int get_weight(){
return this.weight;
}
public int get_height(){
return this.height;
}
public static void main(String[] args){
Student a = new Student("Gun" , 32075, 26, 80, 174);
Student b = new Student("Rit" , 32078, 25, 70, 170);
Student c = new Student("Frame" , 32080, 19, 58, 173);
Student d = new Student("Coffee" , 32057, 18, 50, 168);
Student e = new Student("Boat" , 32087, 16, 60, 165);
Student [] data = {a,b,c,d,e};
BMI(data);
}
public static void BMI(Student [] data){
int i = 0;
float BMI = 0;
int count = 0;
while(i < data.length){
BMI = data[i].get_weight()*100*100/((data[i].get_height()*(data[i].get_height())));
if(BMI > 25){
System.out.println(data[i].get_name() +" BMI value = " +BMI);
count = count + 1;
}
i += 1 ;
}
System.out.println("Have" + count + "Students");
}
}
Find student BMI.
public class Student{
private String name;
private int ID;
private int age;
private int weight;
private int height;
public Student(String name, int ID,int age,int weight,int height){
this.name = name;
this.ID = ID;
this.age = age;
this.weight = weight;
this.height = height;
}
public String get_name(){
return this.name;
}
public int get_ID(){
return this.ID;
}
public int get_age(){
return this.age;
}
public int get_weight(){
return this.weight;
}
public int get_height(){
return this.height;
}
public static void main(String[] args){
Student a = new Student("Gun" , 32075, 26, 80, 174);
Student b = new Student("Rit" , 32078, 25, 70, 170);
Student c = new Student("Frame" , 32080, 19, 58, 173);
Student d = new Student("Coffee" , 32057, 18, 50, 168);
Student e = new Student("Boat" , 32087, 16, 60, 165);
Student [] data = {a,b,c,d,e};
BMI(data);
}
public static void BMI(Student [] data){
int i = 0;
float BMI = 0;
while(i < data.length){
BMI = data[i].get_weight()*100*100/((data[i].get_height()*(data[i].get_height())));
System.out.println(data[i].get_name() +" BMI value = " +BMI);
i += 1 ;
}
}
}
private String name;
private int ID;
private int age;
private int weight;
private int height;
public Student(String name, int ID,int age,int weight,int height){
this.name = name;
this.ID = ID;
this.age = age;
this.weight = weight;
this.height = height;
}
public String get_name(){
return this.name;
}
public int get_ID(){
return this.ID;
}
public int get_age(){
return this.age;
}
public int get_weight(){
return this.weight;
}
public int get_height(){
return this.height;
}
public static void main(String[] args){
Student a = new Student("Gun" , 32075, 26, 80, 174);
Student b = new Student("Rit" , 32078, 25, 70, 170);
Student c = new Student("Frame" , 32080, 19, 58, 173);
Student d = new Student("Coffee" , 32057, 18, 50, 168);
Student e = new Student("Boat" , 32087, 16, 60, 165);
Student [] data = {a,b,c,d,e};
BMI(data);
}
public static void BMI(Student [] data){
int i = 0;
float BMI = 0;
while(i < data.length){
BMI = data[i].get_weight()*100*100/((data[i].get_height()*(data[i].get_height())));
System.out.println(data[i].get_name() +" BMI value = " +BMI);
i += 1 ;
}
}
}
วันอาทิตย์ที่ 1 พฤศจิกายน พ.ศ. 2558
Display each student record.
public class Students {
private String name;
private int ID;
private int age;
private int weight;
private int height;
public Students(String name, int ID, int age, int weight, int height){
this.name = name;
this.ID = ID;
this.age = age;
this.weight = weight;
this.height = height;
}
public void display(){
System.out.println( "Name:"+this.name );
System.out.println("ID: " +this.ID);
System.out.println("Age: " +this.age);
System.out.println("Weight: " +this.weight);
System.out.println("height: " +this.height);
System.out.println();
}
public static void main(String[] args) {
Students a = new Students ("Gun", 32075, 26, 70, 174);
Students b = new Students ("Rit", 32078, 25, 60, 170);
Students c = new Students ("Frame", 32080, 19, 58, 173);
Students d = new Students ("Boat", 32057, 16, 65, 168);
Students [] data = {a, b, c, d};
display(data);
}
public static void display(Students [] data){
int i = 0;
while(i < data.length){
data[i].display();
i = i + 1 ;
}
}
}
private String name;
private int ID;
private int age;
private int weight;
private int height;
public Students(String name, int ID, int age, int weight, int height){
this.name = name;
this.ID = ID;
this.age = age;
this.weight = weight;
this.height = height;
}
public void display(){
System.out.println( "Name:"+this.name );
System.out.println("ID: " +this.ID);
System.out.println("Age: " +this.age);
System.out.println("Weight: " +this.weight);
System.out.println("height: " +this.height);
System.out.println();
}
public static void main(String[] args) {
Students a = new Students ("Gun", 32075, 26, 70, 174);
Students b = new Students ("Rit", 32078, 25, 60, 170);
Students c = new Students ("Frame", 32080, 19, 58, 173);
Students d = new Students ("Boat", 32057, 16, 65, 168);
Students [] data = {a, b, c, d};
display(data);
}
public static void display(Students [] data){
int i = 0;
while(i < data.length){
data[i].display();
i = i + 1 ;
}
}
}
สมัครสมาชิก:
บทความ (Atom)
Link Video Presentation Resort Managemant System Project.
Video Presentation Resort Managemant System Project. จัดทำโดย พากษ์เสียง: คุณาสิน ทองมณี 5801012620011 ลำดับภาพ: สุพิชชา ศรีศิริ...
-
- 1NF หรือ Fisrt Normal Form มีเงื่อนไขอยู่ว่า ต้องไม่มีคอลลัมน์ใดในตารางที่มีค่ามากกว่า 1 ค่า หรือที่เรียกว่า Atomic ซึ่งหมายถึง ข้อมูลที่...
-
เนื่องจากวันที่ 27 กุมภาพันธ์ ถึง 22 มีนาคม 2561 เป็นช่วงเวลาของการสอบกลางภาค ซึ่งทำให้ต้องแบ่งเวลาในการทำงานและอ่านหนังสือสอบอย่างหนัก จึง...