Thursday, February 4, 2010

LABEXERCISES_iT123B

package Entity;

/**
*
* @author Administrator
*/
public class Student {

public static String size() {
throw new UnsupportedOperationException("Not yet implemented");
}



private String name;
private String studesId;
private int age;
private String address;
private Course course;

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public Course getCourse() {
return course;
}

public void setCourse(Course course) {
this.course = course;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getStudesId() {
return studesId;
}

public void setStudesId(String studesId) {
this.studesId = studesId;
}

public Student(String name, String studesId, int age, String address, Course course) {
this.name = name;
this.studesId = studesId;
this.age = age;
this.address = address;
this.course = course;
}

public Student() {
}



public String displayStudesmenu(){
return"\nName:"+name +";" +"Student ID:"+studesId +";" +"Age:"+age+"Address:"+address +";" +"Student Course:"+course;
}
}

package Entity;

/**
*
* @author Administrator
*/
public class Course {

private String coursedescription;

public String getCoursedescription() {
return coursedescription;
}

public void setCoursedescription(String coursedescription) {
this.coursedescription = coursedescription;
}

public Course(String coursedescription) {
this.coursedescription = coursedescription;
}

public Course() {
}


public String displayCourse(){
return"\nCourse:"+coursedescription;

}
}

package demo;

import java.util.*;


import java.util.ArrayList;
import Entity.Course;
import Entity.Student;

/**
*
* @author Administrator
*/
public class ArrayListTest {

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);



ArrayList student = new ArrayList();

Course BSBA = new Course("Bachelor of Science in Business Administration");
Course BSIT = new Course("Bachelor of Science and Information Technology ");
Course BSBS = new Course("Bachelor of Secondary Education major in Biological Science ");
Course BSN = new Course("Bachelor of Science in Nursing ");
Student st1 = new Student("Malacaste, Annelyn B.", "2008-0079", 18, "Dawan", BSIT);
Student st2 = new Student("Magdagasang, Jonalyn B.", "2006-0179", 19, "Caraga", BSN);
Student st3 = new Student("Porio, Ciera Patrice P.", "2008-0139", 17, "Tamisan", BSBS);
Student st4 = new Student("Israel, Melanie S.", "2008-0009", 18, "Urban", BSIT);
Student st5 = new Student("Legspi, Mary Grace M.", "2008-0132", 19, "Pantukan", BSIT);

student.add(st1);
student.add(st2);
student.add(st3);
student.add(st4);
student.add(st5);

String result = "A";
int i;
while (result.equals("a") || result.equals("A")) {


System.out.println("STUDENT MENU");
System.out.println("");

System.out.println("Press 1 to Insert Student");
System.out.println("Press 2 to Delete Student");
System.out.println("Press 3 to Count no. of Student");
System.out.println("Press 4 to Clear the list of Student");
System.out.println("Press 5 to Display individual Student");
System.out.println("Press 6 to Display the list of Student");
System.out.println("");
System.out.println("Please pick your choice");
int choice = scan.nextInt();





switch (choice) {

case 1:
System.out.println("You Choose: Insert Student");

String name;
System.out.print("Enter Name: ");
name = scan.next();
System.out.print("Enter Age: ");
int age = scan.nextInt();
System.out.print("Enter Address: ");
String address = scan.next();
System.out.print("Enter ID No. ");
String ID = scan.next();
System.out.println("Course Description Menu: ");
System.out.println("BSIT: Batchelor of Science in Information Tsghnology");
System.out.println("BSN: Bachelor of Science in Nursing");
System.out.println("BSBA: Baghelor of Sgience in Business Adninictration ");
System.out.println("BSBS: Baghelor of Sgience in Biological Science");
System.out.print("Enter Course: ");
String C = scan.next();
Student s6;
if (C.equals("BSIT")) {
s6 = new Student(name, ID, age, address, BSIT);
} else if (C.equals("BSN")) {
s6 = new Student(name, ID, age, address, BSN);
} else if (C.equals("BSBA")) {
s6 = new Student(name, ID, age, address, BSBA);
} else {
s6 = new Student(name, ID, age, address, BSBA);
}
student.add(s6);
System.out.println();
for (int n = 0; n < student.size(); n++) {
System.out.println(student.get(n).displayStudesmenu() + "\n");
}
break;
case2:
System.out.println("You want to delete student? Ahm, ok!");
System.out.println("Enter index you want delete.");
try {
int a = scan.nextInt();
student.removeAll(student);
System.out.println("You've succesfully done it! Congrats!!");
}
catch (Exception exception) {
System.out.println("Nothing found!");

System.out.println();
}
break;

case3:
System.out.println("Count the student?!Wish is granted!");
System.out.println();
System.out.println("The student on the list are only" + Student.size());

break;

case4:
System.out.println("Clear the list?! Let's try.....");
student.clear();
System.out.println("Incredible! The list is cleared completely!!");

break;

case5:
System.out.println("Want to display individual students? Fine, whatever!");
System.out.println("Enter the index you want");
try {
int b = scan.nextInt();
System.out.println(student.get(i).displayStudesmenu());
} catch (Exception ex) {
System.out.println("Nothing found!");
}
break;


case6:
System.out.println("Display the list of student");
System.out.println();
for (int a = 0; a < student.size(); a++) {
System.out.println(student.get(a).displayStudesmenu() + "\n");

break;
}

default: {
System.out.println("Hey!You're out of the world are you? Look, your choice is out bound! Try again later.......");

}

System.out.println("By the way do you want to continue?Annie or exit");



result = scan.next();



}


}
}
}
####################################################################################
package demo;

/**
*
* LabExercise2
*/
import java.util.*;
public class Inverse{

public static void main(String[] args){

LinkedList firstlist = new LinkedList();
LinkedList secondlist = new LinkedList();

char me[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',};

for(int anne=0; anne<10; anne++ )
{
firstlist.add(me[anne]);
}

System.out.println("\n");
System.out.println("The elements of the firstlist are: ");

for(int l=0; l {
System.out.print("," + firstlist.get(l));
}

System.out.println("\n");
System.out.println("\nThe elements of the secondlist are: ");

for(int y=9; y>=secondlist.size(); y-- ){
if (me[y]==me[9]) {
System.out.print(" " + me[9]);
}

else{
System.out.print("," + me[y]);
}

}
System.out.println();
}
}
##########################################################################################
package demo;



/**
*
* LabExercise2
*/
import java.util.*;

public class Random {

public static void main(String[] args) {

LinkedList random = new LinkedList();

Random r= new Random();
int sum = 0;

for (int index = 0; index < 30; index++) {

int a = r.main(100);
random.add(r);
sum = sum + a;
}
for (int a = 0; a < random.size(); a++) {
System.out.println(random.get(a));
}
int average = sum / 25;

System.out.println("\n");
System.out.print("The sum is: " + sum);
System.out.println("\n");
System.out.print("The average is: " + average);

}
}

No comments:

Post a Comment