[go: up one dir, main page]

0% found this document useful (0 votes)
19 views6 pages

07 Lab07

Uploaded by

4qtycsnpsf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views6 pages

07 Lab07

Uploaded by

4qtycsnpsf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

public class Student{


public String name;
public String prog;
Public Student(String nm,String program){
name=nm;
prog=program;
}
public void updateName(String nm){
name=nm;
}
public String accessName(){
return name;
}
public void updateProgram(String program){
prog=program;
}
public String accessProgram(){
return prog;
}
}

2.public class Toy{


public String name;
public int price;
public Toy (String obj, int prc) {
name=obj;
price=prc;
System.out.println("A new toy has been made!");
}
public void updatePrice (int prc){
price=prc;
}
public void updateName(String obj) {
System.out.println("Changing old name: "+name);
name=obj;
System.out.println("New name: "+name);
}
public void showPrice(){
System.out.println("price: "+price);
}
}

3.public class Parcel{


public String name;
public int weight;
public int addWeight;
public double fee;
public Parcel(){
}
public Parcel(String nm){
name=nm;
}
public Parcel(String nm,int x){
name=nm;
weight=x;
}
public void printDetails(){
if (name==null){
System.out.println("Set name first");
}else{
System.out.println("Name: "+name+"\n"+"Total Weight: "+weight+"\n"+"Total
Fee: "+fee);
}
}
public void calcFee(String nm){
if(nm=="Dhanmondi"){
int location_charge=50;
fee=(weight*20)+location_charge;
}else{
int location_charge=0;
fee=(weight*20)+location_charge;
}
}
public void addWeight(int x){
weight+=x;
}
}

4.public class Shape2D{


public String name;
public double area;
public int x,y,z;
public Shape2D(int length){
name="square";
x=length;
System.out.println("A Square has been created with length: "+length);
}
public Shape2D(int length,int breadth){
name="rectangle";
x=length;
y=breadth;
System.out.println("A Rectangle has been created with length: "+length+"
and breadth: "+breadth);
}
public Shape2D(int height,int base,String shape){
name="tri1";
x=height;
y=base;
System.out.println("A "+shape+" has been created with height: "+height+"
and base: "+base);
}
public Shape2D(int side1,int side2,int side3){
name="tri2";
x=side1;
y=side2;
z=side3;
System.out.println("A triangle has been created with the following sides:
"+side1+","+side2+","+side3);
}
public void area(){
if(name=="square"){
area=x*x;
System.out.println("the area of the Square is: "+area);
}else if(name=="rectangle"){
area=x*y;
System.out.println("the area of the Rectangle is: "+area);
}else if(name=="tri1"){
area=0.5*x*y;
System.out.println("the area of the triangle is: "+area);
}else{
int s=(x+y+z)/2;
area= Math.sqrt(s*(s-x)*(s-y)*(s-z));
System.out.println("the area of the triangle is: "+area);
}
}

5.public class Book{


public String name;
public int price;
public String author;
public Book(String x){
name=x;
}
public Book(String x,String y){
name=x;
author=y;
}
public Book(String x,String y,int z){
name=x;
author=y;
price=z;
}
public void displayDetails(){
if(price!=0&&author!=null){
System.out.println("Title: "+name+" Author: "+author+" Price: "+price);
}else if(author!=null){
System.out.println("Title: "+name+" Author: "+author);
}else if(author==null){
System.out.println("Title: "+name+" Price: "+price);
}else{
System.out.println("Title: "+name);
}
}
public void setDetails(int x){
price=x;
}
public void setDetails(String x,int y){
price=y;
author=x;
}
}

6.public class Product{


public String name;
private int quantity;
private double price;
public boolean status;
public Product(){
if(name==null){
name="unknown";
}
}
public Product(String nm,double $){
name=nm;
price=$;
}
public void setQuantity(int amount){
quantity=amount;
}
public int getQuantity(){
return quantity;
}
public double getPrice(){
return price;
}
public void displayInfo(){
System.out.println("Product name: "+name+"\n"+"Price: "+price);
}
public void displayInfo(boolean x){
status=x;
if(status==true){
System.out.println("Product name: "+name+"\n"+"Price: "+price+"\
n"+"Quantity: "+quantity);
}
}

7.public class Student{


private int id;
private double cgpa;
public String[] course=new String[4];
public int coursecount=0;
public Student(int x){
id=x;
}
public Student(int x,double result){
id=x;
cgpa=result;
}
public void addCourse(String sub){
if(cgpa==0.0){
System.out.println("Failed to add "+sub+"\n"+"Set CG first");
}else if(cgpa<3&&coursecount==3){
System.out.println("Failed to add "+sub+"\n"+"CG is low. Can't add
more than 3 courses.");
}else{
course[coursecount]=sub;
coursecount++;
}
}
public void addCourse(String[] sub){
if(cgpa<3){
for(coursecount=0;coursecount<=3;coursecount++){
if(coursecount==3){
break;
}else{
course[coursecount]=sub[coursecount];
}
}
}else if(cgpa>3){
for(coursecount=0;coursecount<=4;coursecount++){
if(coursecount==4){
System.out.println("Failed to add "+sub[coursecount]+"\n"+"Maximum
4 courses allowed.");
break;
}else{
course[coursecount]=sub[coursecount];
}
}
}
}
public void rmAllCourse(){
course=new String[4];
}
public void setCG(double x){
cgpa=x;
}
public void setID(int x){
id=x;
}
public void showAdvisee(){
System.out.println("Student id: "+id+","+"CGPA: "+cgpa+"\n"+"Added courses
are: ");
for(int i=0;i<coursecount;i++){
if(course[i]==null){
System.out.println("No courses added.");
break;
}else{
System.out.print(course[i]+" ");
}
}
System.out.println();
}
}

8.public class ABCserver{


public String server_name;
public int members=0;
public String[] role=new String[10];
public int x=10;
public String[] team= new String[x];
public int count=0;
public ABCserver(){
server_name="Default";
}
public ABCserver(String name,int limit){
server_name=name;
x=limit;
}
public void addMembers(String name){
team[members]=name;
role[members]="Rising Hero";
System.out.println("Rising Hero is added.");
members++;
}
public void addMembers(String name,String power){
if(members>=x){
System.out.println("Sorry, maximum capacity exceeded!");
}else{
team[members]=name;
role[members]=power;
System.out.println(power+" is added.");
members++;
}
}
public void details(){
System.out.println("Server Name: "+server_name+"\n"+"Member Capacity:
"+x+"\n"+"Total Members:"+members);
System.out.println("Members: "+"\n");
for(int i=0;i<members;i++){
System.out.println("Name:Role --> "+team[i]+":"+role[i]);
}

}
}

You might also like