📄 hw8_3.java
字号:
//题目:8-03,试设计一类,使用同一个名称的method来传入数据
import java.io.*;
class CSet
{
private String col;
private int width;
private int height;
public void set(String color)
{
col=color; //(a)可输入长方形的颜色
}
public void set(int w,int h)
{
width=w; //(b)可输入长方形的宽和高
height=h;
}
public void set(String color,int w,int h)
{
col=color; //(c)可输入长方形的颜色、宽和高
width=w;
height=h;
}
public void show()
{
System.out.println("\n长方形的颜色为 : "+col);
System.out.println("\n长方形宽为: "+width+" 长方形高为:"+height);
}
}
public class hw8_3
{
public static void main(String args[]) throws IOException
{
int w,h; //声明宽、长变量,并给予赋值
String color,k;
CSet rect1 ;
rect1 = new CSet();
System.out.print("\n请输入颜色:: ");
color=input();
System.out.print("\n请输入宽度:: ");
k=input();
w=Integer.parseInt(k);
System.out.print("\n请输入高度:: ");
k=input();
h=Integer.parseInt(k);
rect1.set(color); //设置长方形的颜色
rect1.set(w,h); //设置长方形的宽、高
rect1.show();
rect1.set(color,w,h);//设置长方形的颜色和宽、高
rect1.show();
}
public static String input() throws IOException //输入函数
{
String str;
BufferedReader buf;
buf=new BufferedReader(new InputStreamReader(System.in));
str=buf.readLine();
return str;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -