You are on page 1of 8

LAB-7-PRE-1

package sample_2;

public class GeometricShape {


static String bordercolour;
static String fillcolour;
static boolean fill;
static double borderwidth;
static void setBor(String b)
{
if(b.equals("red")||b.equals("blue")||b.equals("green")||b.equals("white")|
|b.equals("black"))
{
bordercolour=b;
}
}
static void setFillColour(String b)
{
if(b.equals("red")||b.equals("blue")||b.equals("green")||b.equals("white")|
|b.equals("black"))
{
fillcolour=b;
}
}
static void setBorderWidth(double b)
{
if(b>0 && b<2)
{
borderwidth=b;
}
else
System.out.println("shape cant be formed");
}
static double getBorderWidth()
{
return(borderwidth);
}
static String getBor()
{
return(bordercolour);
}
static String getFillColour()
{
return(fillcolour);
}

static void setFill(boolean v)


{
if(v==true)
fill=v;
else
System.out.println("wrong input");
}
static boolean getFill()
{
return(fill);
}
}

package sample_2;
import java.util.Scanner;
public class Rectangle extends GeometricShape{
double length;
double width;
void setLen(double l)
{
if(l>0 )
{
length=l;

}
}
void setBred(double b)
{
if(b>0 )
{
width=b;

}
}
double getLen()
{
return(length);
}
double getBred()
{
return(width);
}
public String toString()
{
return("rectangle: length: "+getLen()+" "+"breadth: "+getBred()+"
bordercolour: "+getBor()+" fill: "+getFill()+" fillcolour "+getFillColour()+"
borderwidth: "+getBorderWidth());
}
public void read()
{
Scanner s=new Scanner(System.in);
System.out.println("enter
bordercolour,fillcolour,fill,length,breadth,borderwidth");
bordercolour=s.next();
fillcolour=s.next();
fill=s.nextBoolean();
length=s.nextDouble();
width=s.nextDouble();
borderwidth=s.nextDouble();
setLen(length);
setBred(width);
setBor(bordercolour);
setFillColour(fillcolour);
setBorderWidth(borderwidth);
setFill(fill);
}
}
package sample_2;

public class Demo7_1 {


public static void main(String args[]) {

Rectangle r=new Rectangle();


r.read();
System.out.println(r.toString());
}
}
OUTPUT
enter bordercolour,fillcolour,fill,length,breadth,borderwidth
red
red
true
2
3.1
2.3
shape cant be formed
rectangle: length: 2.0 breadth: 3.1 bordercolour: red fill: true fillcolour red
borderwidth: 2.3
PART-2
package sample_2;

import java.util.Scanner;

public class Circle extends GeometricShape{


static double radius;

static void setRad(double r)


{
if(r>0)
{
radius=r;
}
}

public String toString()


{
return("Circle: radius: "+getRadius()+" bordercolour: "+getBor()+"
fill: "+getFill()+" fillcolour "+getFillColour()+" borderwidth:
"+getBorderWidth());
}

double getRadius()
{
return(radius);
}

public void read()


{
Scanner s=new Scanner(System.in);
System.out.println("enter
bordercolour,fillcolour,fill,radius,borderwidth");
bordercolour=s.next();
fillcolour=s.next();
fill=s.nextBoolean();
radius=s.nextDouble();
borderwidth=s.nextDouble();
setRad(radius);
setBor(bordercolour);
setFillColour(fillcolour);
setBorderWidth(borderwidth);
setFill(fill);
}
}

package sample_2;
public class Demo711 {
public static void main(String args[]) {

Circle c=new Circle();


c.read();
System.out.println(c.toString());
}

OUTPUT
enter bordercolour,fillcolour,fill,radius,borderwidth
white
white
true
7.8
2
shape cant be formed
Circle: radius: 7.8 bordercolour: white fill: true fillcolour white borderwidth:
2.0

THE END
post lab
package sample_2;
import java.util.Scanner;
public class Account {
static String an;
static double bal,rate,dare;
void read()
{
Scanner s=new Scanner(System.in);
System.out.println("enter account number,balance,interest rate");
an=s.next();
bal=s.nextDouble();
rate=s.nextDouble();
setbal(bal);
setinterest(rate);
setAC(an);

}
static void setbal(double b)
{
if(b>0)
{
bal=b;

}
static void setinterest(double i)
{
if(i>0)
{
rate=i;

}
static void setAC(String a)
{
if(a.length()==4 && Integer.parseInt(a)>0)
{
an=a;
}
}
static String getAC()
{
return(an);
}
static double getinterest()
{
return(rate);
}

static double getbal()


{
return(bal);
}

static void withdraw()


{
double amount;
double remain;
Scanner s=new Scanner(System.in);
System.out.println("Please enter the amount to withdraw");
amount=s.nextDouble();
dare=amount;
System.out.println("PLEASE COLLECT YOUR CASH");
System.out.println("remaing balance is: ");
remain=bal-amount;
System.out.println(remain);
bal=remain;
System.out.println("PRESS 3 TO EXIT");
}

static void deposit()


{
double amount;
double remain;
Scanner s=new Scanner(System.in);
System.out.println("Please enter the amount to deposit");
amount=s.nextInt();
System.out.println("Please place your cash");
System.out.println("DEPOSIT SUCCESSFUL");
System.out.println("your total balance is: ");
remain=bal+amount;
bal=remain;
System.out.println(remain);
}
public String toString()
{
return("ACCOUNT NUMBER: "+getAC()+" balance: "+getbal()+" Interest:
"+getinterest());
}

}
package sample_2;
import java.util.Scanner;
public class CheckingAccount extends Account{
void display()
{
read();
Scanner s=new Scanner(System.in);
int choice;
while(true)
{
System.out.println("enter 1: withdraw");
System.out.println("enter 2: deposit");
System.out.println("enter 3:exit");
System.out.println("enter choice");
choice=s.nextInt();
if(choice==1)
{ if(dare<=20000)
withdraw();
else
System.out.println("your overdraft limit is exceeded");
}
if(choice==2)
{

deposit();
}
if(choice==3)
{
System.out.println("TRANSACTION COMPLETED");
break;
}
}
System.out.println(toString());

}
}

package sample_2;
import java.util.Scanner;
public class SavingAccount extends Account{
void display()
{
read();
Scanner s=new Scanner(System.in);
System.out.println("enter choice");
int choice;
while(true)
{
System.out.println("enter 1: withdraw");
System.out.println("enter 2: deposit");
System.out.println("enter 3:exit");
System.out.println("enter choice");
choice=s.nextInt();
if(choice==1)
{ if(bal>0)
withdraw();
else
System.out.println("your account is overdrawn");
}
if(choice==2)
{

deposit();
}
if(choice==3)
{
System.out.println("TRANSACTION COMPLETED");
break;
}
}
System.out.println(toString());

}
}

You might also like