public class Student{
private String name;
private int idNumber;
private int age;
private int weight;
private int height;
public Student(String name,int idNumber,int age,int weight,int height){
this.name = name;
this.idNumber = idNumber;
this.age = age;
this.weight = weight;
this.height = height;
}
public String get_name(){
return this.name;
}
public int get_idNumber(){
return this.idNumber;
}
public int get_age(){
return this.age;
}
public int get_weight(){
return this.weight;
}
public int get_height(){
return this.height;
}
public static void count_below_weight_50(Student[] studentRec){
int index = 0;
int count = 0;
while(index < studentRec.length){
if(50 > studentRec[index].get_weight())
count += 1;
index += 1;
}
System.out.println("Number of students with weight < 50 is "+count);
}
public static void main(String[] args){
Student[] studentRec = { new Student( "Mabel" , 44592 , 19 , 49 , 155 ),
new Student( "Mike" , 44593 , 32 , 65 , 173 ),
new Student( "Nick" , 44594 , 27 , 61 , 165 ),
new Student( "Jack" , 44595 , 35 , 68 , 158 ),
new Student( "Lucy" , 44596 , 55 , 75 , 175),
new Student( "Max" , 44597 , 18 , 56 , 163 ),
new Student( "Luck" , 44598 , 20 , 58 , 169 ) };
count_below_weight_50(studentRec);
}
}
Lab 8 Java Generic 10 ( Display student records with weight < 50 )
public class Student{
private String name;
private int idNumber;
private int age;
private int weight;
private int height;
public Student(String name,int idNumber,int age,int weight,int height){
this.name = name;
this.idNumber = idNumber;
this.age = age;
this.weight = weight;
this.height = height;
}
public String get_name(){
return this.name;
}
public int get_idNumber(){
return this.idNumber;
}
public int get_age(){
return this.age;
}
public int get_weight(){
return this.weight;
}
public int get_height(){
return this.height;
}
public static void display_weight_below_50_data(Student[] studentRec){
int index = 0;
System.out.println("--Student records with weight < 50--");
while(index < studentRec.length){
if(50 > studentRec[index].get_weight()){
System.out.println("---"+(index+1)+"---");
System.out.println("Student name : "+studentRec[index].get_name());
System.out.println("ID : "+studentRec[index].get_idNumber());
System.out.println("Age : "+studentRec[index].get_age()+" years");
System.out.println("weight : "+studentRec[index].get_weight()+" Kg");
System.out.println("Height : "+studentRec[index].get_height()+" cm");
System.out.println("");
}
index += 1;
}
}
public static void main(String[] args){
Student[] studentRec = { new Student( "Mabel" , 44592 , 19 , 49 , 155 ),
new Student( "Mike" , 44593 , 32 , 65 , 173 ),
new Student( "Nick" , 44594 , 27 , 61 , 165 ),
new Student( "Jack" , 44595 , 35 , 68 , 158 ),
new Student( "Lucy" , 44596 , 55 , 75 , 175),
new Student( "Max" , 44597 , 18 , 56 , 163 ),
new Student( "Luck" , 44598 , 20 , 58 , 169 ) };
display_weight_below_50_data(studentRec);
}
}
Lab 8 Java Generic 11 ( Create class Banner for printing a banner 1 )
public class Alphabet{
private String Line1;
private String Line2;
private String Line3;
private String Line4;
private String Line5;
public Alphabet(String Line1,String Line2,String Line3,String Line4,String Line5){
this.Line1 = Line1;
this.Line2 = Line2;
this.Line3 = Line3;
this.Line4 = Line4;
this.Line5 = Line5;
}
public void display_alphabet_L1(){
System.out.print(this.Line1);
}
public void display_alphabet_L2(){
System.out.print(this.Line2);
}
public void display_alphabet_L3(){
System.out.print(this.Line3);
}
public void display_alphabet_L4(){
System.out.print(this.Line4);
}
public void display_alphabet_L5(){
System.out.print(this.Line5);
}
public static void draw_alphabet(Alphabet[] alphabet_group,String word){
int index_print = 0;
while(index_print < 5){
int index_word = 0;
while(index_word < word.length()){
if(word.charAt(index_word) == 'N'){
//System.out.print("1");
print_func(alphabet_group,index_print,0);
}
else if(word.charAt(index_word) == 'O'){
//System.out.print("2");
print_func(alphabet_group,index_print,1);
}
else if(word.charAt(index_word) == 'B'){
//System.out.print("3");
print_func(alphabet_group,index_print,2);
}
index_word += 1;
}
System.out.println("");
index_print += 1 ;
}
}
public static void print_func(Alphabet[] alphabet_group,int index_print,int alphabet_index){
if(index_print == 0){
alphabet_group[alphabet_index].display_alphabet_L1();
}
else if(index_print == 1){
alphabet_group[alphabet_index].display_alphabet_L2();
}
else if(index_print == 2){
alphabet_group[alphabet_index].display_alphabet_L3();
}
else if(index_print == 3){
alphabet_group[alphabet_index].display_alphabet_L4();
}
else if(index_print == 4){
alphabet_group[alphabet_index].display_alphabet_L5();
}
}
public static void main(String[] args){
Alphabet[] alphabet_group = { new Alphabet(
" # # ",
" ## # ",
" # # # ",
" # # # ",
" # ## " ),
new Alphabet(
" #### ",
" # # ",
" # # ",
" # # ",
" #### " ),
new Alphabet(
" ##### ",
" # # ",
" ##### ",
" # # ",
" ##### " ) };
draw_alphabet(alphabet_group,"NOOB");
}
}
Lab 8 Java Generic 12 ( Create class Banner for printing a banner 2 )
public class Alphabet{
private String Line1;
private String Line2;
private String Line3;
private String Line4;
private String Line5;
public Alphabet(String Line1,String Line2,String Line3,String Line4,String Line5){
this.Line1 = Line1;
this.Line2 = Line2;
this.Line3 = Line3;
this.Line4 = Line4;
this.Line5 = Line5;
}
public void display_alphabet_L1(){
System.out.print(this.Line1);
}
public void display_alphabet_L2(){
System.out.print(this.Line2);
}
public void display_alphabet_L3(){
System.out.print(this.Line3);
}
public void display_alphabet_L4(){
System.out.print(this.Line4);
}
public void display_alphabet_L5(){
System.out.print(this.Line5);
}
public void display_star_alphabet_L1(){
System.out.print(this.Line1);
}
public void display_star_alphabet_L2(){
System.out.print(this.Line2);
}
public void display_star_alphabet_L3(){
System.out.print(this.Line3);
}
public void display_star_alphabet_L4(){
System.out.print(this.Line4);
}
public void display_star_alphabet_L5(){
System.out.print(this.Line5);
}
public String get_alphabet_L1(){
return this.Line1;
}
public String get_alphabet_L2(){
return this.Line2;
}
public String get_alphabet_L3(){
return this.Line3;
}
public String get_alphabet_L4(){
return this.Line4;
}
public String get_alphabet_L5(){
return this.Line5;
}
public static void draw_alphabet_star(Alphabet[] alphabet_group,String print){
int index = 0;
while( index < print.length() ){
if (print.charAt(index) == '#'){
System.out.print("*");
}
else{
System.out.print(" ");
}
index += 1;
}
}
public static void draw_alphabet(Alphabet[] alphabet_group,String word){
int index_print = 0;
while(index_print < 5){
int index_word = 0;
while(index_word < word.length()){
if(word.charAt(index_word) == 'N'){
//System.out.print("1");
print_func(alphabet_group,index_print,0);
}
else if(word.charAt(index_word) == 'O'){
//System.out.print("2");
print_func(alphabet_group,index_print,1);
}
else if(word.charAt(index_word) == 'B'){
//System.out.print("3");
print_func(alphabet_group,index_print,2);
}
index_word += 1;
}
System.out.println("");
index_print += 1 ;
}
}
public static void print_func(Alphabet[] alphabet_group,int index_print,int alphabet_index){
if(index_print == 0){
draw_alphabet_star(alphabet_group,alphabet_group[alphabet_index].get_alphabet_L1());
}
else if(index_print == 1){
draw_alphabet_star(alphabet_group,alphabet_group[alphabet_index].get_alphabet_L2());
}
else if(index_print == 2){
draw_alphabet_star(alphabet_group,alphabet_group[alphabet_index].get_alphabet_L3());
}
else if(index_print == 3){
draw_alphabet_star(alphabet_group,alphabet_group[alphabet_index].get_alphabet_L4());
}
else if(index_print == 4){
draw_alphabet_star(alphabet_group,alphabet_group[alphabet_index].get_alphabet_L5());
}
}
public static void main(String[] args){
Alphabet[] alphabet_group = { new Alphabet(
" # # ",
" ## # ",
" # # # ",
" # # # ",
" # ## " ),
new Alphabet(
" #### ",
" # # ",
" # # ",
" # # ",
" #### " ),
new Alphabet(
" ##### ",
" # # ",
" ##### ",
" # # ",
" ##### " ) };
draw_alphabet(alphabet_group,"NOOB");
}
}