0% found this document useful (0 votes)
11 views

Assigment 8

Uploaded by

aziad711
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Assigment 8

Uploaded by

aziad711
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Name: Farida tamer salah elmaghraby

ID:221005756
1.
public class Rectangle1 {
private int width1;
private int height1;
public Rectangle1()
{
width1=1;
height1=1;
}
public void setWidth1(int y)
{width1=y;}
public void setHeight1(int x)
{height1=x;}
public int GetWidth()
{return width1;}
public int GetHeight()
{return height1;}

public int Area()


{return (width1*height1);}
public int paremeter()
{return 2*(width1*height1);}

public void printInfo(){


System.out.println("Width is "+width1);
System.out.println("Height is "+height1);
System.out.println("Area is "+Area());
System.out.println("Permieter is "+paremeter());
}

public String getShape() {


if (GetHeight() > GetWidth()) {
return "Vertical";
} else if (GetHeight() < GetWidth()) {
return "Horizontal";
} else {
return "Square";
}
}

import javax.swing.*;

public class Assignment8 {


public static void main(String[]args ){
Rectangle1 Rec1= new Rectangle1();
Rectangle1 Rec2= new Rectangle1();
int wid=Integer.parseInt(JOptionPane.showInputDialog("Enter size of
width"));
int hig=Integer.parseInt(JOptionPane.showInputDialog("Enter size of
height"));
Rec1.setWidth1(wid);
Rec1.setHeight1(hig);
int wid1=Integer.parseInt(JOptionPane.showInputDialog("Enter second
width size"));
int hig1=Integer.parseInt(JOptionPane.showInputDialog("Enter second
height size"));
Rec2.setWidth1(wid1);
Rec2.setHeight1(hig1);

Rec1.printInfo();
Rec2.printInfo();

boolean largerRectangle = Rec1.Area() >= Rec2.Area();


System.out.println("\nLarger Rectangle Information:");
System.out.println(largerRectangle);
}
}

2.
public class circle {
private double radius;
private int y;
private int x;

public circle()
{
radius=1;
}
public void setRadius(double r)
{ if(r<=0)
r=1;
else
radius=r;}
public void setY(int c)
{y=c;}
public void setX(int cen)
{x=cen;}

public double getRadius()


{return radius;}
public int getY()
{return y;}
public int getX()
{return x;}

public double claculateArea()


{return Math.PI* Math.pow(radius,2);}

public double calculatecircumference()


{ return 2*Math.PI*radius;}
public double calculateDiamter()
{ return 2*radius;}
public void printinfo()
{
System.out.println("The radius is "+radius);
System.out.println("The center is "+x+",\t"+y);
System.out.println("The Area is "+claculateArea());
System.out.println("The circumference is "+calculatecircumference());
System.out.println("The Diamter is "+calculateDiamter());
}

import javax.swing.*;
import java.time.chrono.JapaneseChronology;
public class Ass8 {
public static void main(String[]args){
circle c1= new circle();
circle c2=new circle();

double rad= Double.parseDouble(JOptionPane.showInputDialog("Enter


number of radius"));
int cent=Integer.parseInt(JOptionPane.showInputDialog("Enter number
of center"));
int centr=Integer.parseInt(JOptionPane.showInputDialog("Enter second
number of center "));
c1.setRadius(rad);
c1.setY(cent);
c1.setX(centr);

double rad1= Double.parseDouble(JOptionPane.showInputDialog("Enter


second radius"));
int cent1= Integer.parseInt(JOptionPane.showInputDialog("Enter number
of center"));
int centr1= Integer.parseInt(JOptionPane.showInputDialog("Enter
number of center"));
c2.setRadius(rad1);
c2.setY(cent1);
c2.setX(centr1);

c1.printinfo();
c2.printinfo();
}
}
3.
import javax.swing.*;
public class Book {
private String Title;
private String Author;
private double price;
private int copies;
private int Publish_Year;

public String getTitle() {


return Title;
}

public void setTitle(String title) {


Title = title;
}

public void setAuthor(String author) {


Author = author;
}

public String getAuthor() {


return Author;
}

public double getPrice() {


return price;
}

public void setPrice(double price) {


this.price = price;
}

public int getCopies() {


return copies;
}

public void setCopies(int copies) {


this.copies = copies;
}

public int getPublish_Year() {


return Publish_Year;
}

public void setPublish_Year(int publish_Year) {


Publish_Year = publish_Year;
}

public void getBorrow_Book(int quantity)


{
if(quantity>copies)
JOptionPane.showMessageDialog(null, "sorry, there are"+quantity);
else
copies=copies-quantity;
}
public void ReturnBook()
{
copies++;
}

public void printinfo()


{
String output="";
output+="The title is: "+Title;
output+="The Autor is: "+Author;
output+="The price is: "+price;
output+="The Copies is: "+copies;
output+="The Publish Year is: "+Publish_Year;
JOptionPane.showMessageDialog(null, output);
}
}

import javax.swing.*;
public class A8 {
public static void main(String[]args){
Book b1= new Book();
Book b2= new Book();
Book b3= new Book();

b1.setTitle("Java");
b1.setAuthor("schilat");
b1.setPrice(135.50);
b1.setCopies(10);
b1.setPublish_Year(2022);

b2.setTitle("C#");
b2.setAuthor("deitel");
b2.setPrice(139.99);
b2.setCopies(3);
b2.setPublish_Year(2021);

b3.setTitle("C++");
b3.setAuthor("Deital");
b3.setPrice(130);
b3.setCopies(5);
b3.setPublish_Year(2019);

b1.getBorrowBook(4);
b2.getBorrowBook(3);
b3.getBorrowBook(2);

b1.ReturnBook();
b1.ReturnBook();

String output="";
output+= "\n"+b1.getTitle()+": "+b1.getCopies()+": "+"copies";
output+= "\n"+b2.getTitle()+": "+b2.getCopies()+": "+"copies";
output+= "\n"+b3.getTitle()+": "+b3.getCopies()+": "+"copies";
JOptionPane.showMessageDialog(null, output);
b2.getBorrowBook(3);

}
}
4.
public class Arithmetic {
private int number;
public int getnumber(){
return number;
}
public void setnumber(int n){
if(n<0)
number=1;
else
number=n;
}
public Arithmetic(){number=1;}
public int getfactorial(){
int fact=1;
for(int i=1; i<=number; i++)
fact*=i;
return fact;
}
public int getsquare(){ return number*number;}
public boolean iseven(){
if(number%2==0)
return true;
else
return false;
}
public boolean isprime(){
boolean status= true;
for(int i=2; i<number; i++)
if(number%i==0)
status=false;
if(status==true && number!=1)
return true;
else
return false;
}
}
public class As8 {
public static void main(String[]args){
Arithmetic a1=new Arithmetic();
Arithmetic a2=new Arithmetic();
a1.setnumber(6);
System.out.println("Number: "+a1.getnumber()+"\nFactorial:
"+a1.getfactorial()+"\nsquared value: "+a1.getsquare());
if(a1.iseven()==true)
System.out.println("it is an even number");
else
System.out.println("it is an odd number");
if(a1.isprime())
System.out.println("it is a prime number");
else
System.out.println("it is not a prime number");
}
}

You might also like