package homework2;
import java.text.DecimalFormat;
public class Rectangle {
public static void main(String[] args)
{
DecimalFormat de=new DecimalFormat("##0.0");
Rectangle R1=new Rectangle(4,40);
Rectangle R2=new Rectangle(3.5,35.9);
double x=R1.width,y=R1.height,z=R1.getArea(),t=R1.getPremeter();
System.out.println(x+" "+y+" "+" "+z+" "+t);
x=R2.width;
y=R2.height;
z=R2.getArea();
t=R2.getPremeter();
System.out.println(x+" "+y+" "+" "+de.format(z)+" "+t);
}
double width,height;
Rectangle()
{
width=1;
height=1;
}
Rectangle(double newwidth,double newheight)
{
width=newwidth;
height=newheight;
}
double getArea()
{
return width*height;
}
double getPremeter()
{
return (width+height)*2;
}
}
public static void main(String[] args)
{
DecimalFormat de=new DecimalFormat("##0.0");
Rectangle R1=new Rectangle(4,40);
Rectangle R2=new Rectangle(3.5,35.9);
double x=R1.width,y=R1.height,z=R1.getArea(),t=R1.getPremeter();
System.out.println(x+" "+y+" "+" "+z+" "+t);
x=R2.width;
y=R2.height;
z=R2.getArea();
t=R2.getPremeter();
System.out.println(x+" "+y+" "+" "+de.format(z)+" "+t);
}
double width,height;
Rectangle()
{
width=1;
height=1;
}
Rectangle(double newwidth,double newheight)
{
width=newwidth;
height=newheight;
}
double getArea()
{
return width*height;
}
double getPremeter()
{
return (width+height)*2;
}
}
package homework2;
public class Fan {
public static void main(String[] args)
{
Fan h1=new Fan(3,true,10,"yellow");
Fan h2=new Fan(2,false,5,"blue");
h1.tostring();
h2.tostring();
}
private int speed=1;
boolean on=false;
double radius=5;
String color="blue";
Fan()
{
speed=1;
on=false;
radius=5;
color="blue";
}
Fan(int s,boolean o,double r,String c)
{
speed=s;
on=o;
radius=r;
color=c;
}
int getspeed()
{
return speed;
}
void setspeed(int k)
{
speed=k;
}
boolean geton()
{
return on;
}
void geton(boolean k)
{
on=k;
}
double getradius()
{
return radius;
}
void setradius(double k)
{
radius=k;
}
String getcolor()
{
return color;
}
void setcolor(String k)
{
color=k;
}
void tostring()
{
if(on==true)
{
System.out.println(speed+" "+color+" "+radius);
}
else
{
System.out.println("fan is off"+" "+color+" "+radius);
}
}
package homework2;
import java.lang.*;
import java.text.DecimalFormat;
import java.util.Scanner;
public class QuadraticEquation {
public static void main(String[] args)
{
double x,y,z;
DecimalFormat de=new DecimalFormat("##0.0");
System.out.println("快点输入三个值拉:");
Scanner sc=new Scanner(System.in);
x=sc.nextDouble();
y=sc.nextDouble();
z=sc.nextDouble();
QuadraticEquation h1=new QuadraticEquation(x,y,z);
if(h1.getDiscriminant()>0)
{
System.out.println(de.format(h1.getroot1())+" "+de.format(h1.getroot2()));
}
else if(h1.getDiscriminant()==0)
{
System.out.println(de.format(h1.getroot1()));
}
else
System.out.println("The equation has no roots");
}
private double a,b,c;
QuadraticEquation(double na,double nb,double nc)
{
a=na;
b=nb;
c=nc;
}
double getDiscriminant()
{
return b*b-4*a*c;
}
double getroot1()
{
if(Math.pow(b,2)-4*a*c<0)
return 0;
double z=(Math.sqrt(b*b-4*a*c)-b)/(2*a);
return z;
}
double getroot2()
{
if(Math.pow(b,2)-4*a*c<0)
return 0;
double z=-(Math.sqrt(b*b-4*a*c)+b)/(2*a);
return z;
}
}
package homework2;
import java.util.Scanner;
public class Location {
public int row,column;
public double maxValue;
public static void main(String[] args)
{
int row1,column1;
double[][] a1=new double[100][100];
Scanner sc=new Scanner(System.in);
System.out.println("输入二维数组的行数和列数:");
row1=sc.nextInt();
column1=sc.nextInt();
System.out.println("输入数组:");
for(int i=0;i<row1;i++)
for(int j=0;j<column1;j++)
a1[i][j]=sc.nextDouble();
Location L2=new Location();
L2=locateLargetst(a1,row1,column1);
System.out.println("最大元素及其下标是:"+L2.maxValue+"在("+L2.row+","+L2.column+")");
}
Location()
{
row=0;
column=0;
maxValue=-1;
}
public static Location locateLargetst(double[][]a,int r,int c)
{
Location L1=new Location();
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
{
if(L1.maxValue<a[i][j])
{
L1.maxValue=a[i][j];
L1.row=i;
L1.column=j;
}
}
return L1;
}
}
public static void main(String[] args)
{
Fan h1=new Fan(3,true,10,"yellow");
Fan h2=new Fan(2,false,5,"blue");
h1.tostring();
h2.tostring();
}
private int speed=1;
boolean on=false;
double radius=5;
String color="blue";
Fan()
{
speed=1;
on=false;
radius=5;
color="blue";
}
Fan(int s,boolean o,double r,String c)
{
speed=s;
on=o;
radius=r;
color=c;
}
int getspeed()
{
return speed;
}
void setspeed(int k)
{
speed=k;
}
boolean geton()
{
return on;
}
void geton(boolean k)
{
on=k;
}
double getradius()
{
return radius;
}
void setradius(double k)
{
radius=k;
}
String getcolor()
{
return color;
}
void setcolor(String k)
{
color=k;
}
void tostring()
{
if(on==true)
{
System.out.println(speed+" "+color+" "+radius);
}
else
{
System.out.println("fan is off"+" "+color+" "+radius);
}
}
package homework2;
import java.lang.*;
import java.text.DecimalFormat;
import java.util.Scanner;
public class QuadraticEquation {
public static void main(String[] args)
{
double x,y,z;
DecimalFormat de=new DecimalFormat("##0.0");
System.out.println("快点输入三个值拉:");
Scanner sc=new Scanner(System.in);
x=sc.nextDouble();
y=sc.nextDouble();
z=sc.nextDouble();
QuadraticEquation h1=new QuadraticEquation(x,y,z);
if(h1.getDiscriminant()>0)
{
System.out.println(de.format(h1.getroot1())+" "+de.format(h1.getroot2()));
}
else if(h1.getDiscriminant()==0)
{
System.out.println(de.format(h1.getroot1()));
}
else
System.out.println("The equation has no roots");
}
private double a,b,c;
QuadraticEquation(double na,double nb,double nc)
{
a=na;
b=nb;
c=nc;
}
double getDiscriminant()
{
return b*b-4*a*c;
}
double getroot1()
{
if(Math.pow(b,2)-4*a*c<0)
return 0;
double z=(Math.sqrt(b*b-4*a*c)-b)/(2*a);
return z;
}
double getroot2()
{
if(Math.pow(b,2)-4*a*c<0)
return 0;
double z=-(Math.sqrt(b*b-4*a*c)+b)/(2*a);
return z;
}
}
package homework2;
import java.util.Scanner;
public class Location {
public int row,column;
public double maxValue;
public static void main(String[] args)
{
int row1,column1;
double[][] a1=new double[100][100];
Scanner sc=new Scanner(System.in);
System.out.println("输入二维数组的行数和列数:");
row1=sc.nextInt();
column1=sc.nextInt();
System.out.println("输入数组:");
for(int i=0;i<row1;i++)
for(int j=0;j<column1;j++)
a1[i][j]=sc.nextDouble();
Location L2=new Location();
L2=locateLargetst(a1,row1,column1);
System.out.println("最大元素及其下标是:"+L2.maxValue+"在("+L2.row+","+L2.column+")");
}
Location()
{
row=0;
column=0;
maxValue=-1;
}
public static Location locateLargetst(double[][]a,int r,int c)
{
Location L1=new Location();
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
{
if(L1.maxValue<a[i][j])
{
L1.maxValue=a[i][j];
L1.row=i;
L1.column=j;
}
}
return L1;
}
}
}