未分类题

阅读以下说明和JAVA 2代码,填入(n)处。
[说明]
以下JAVA程序设计了类CSet,使用同一个名称(set)的method来传入数据。仔细阅读[代码6-1)、[代码6-2]和[代码6-3]和相关注释,将程序补充完整。
[代码6-1]
import java.io.*;
class CSet
{
private int width;
private int height;
(1)
public void set(String color)
{
col=color; //(a)可输入长方形的颜色
}
public void set (iht 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');
}
}
[代码6-2]
public class hw8_3
{
public static void main (String args[]) throws IOException
{
intw, h; //声明宽、长变量,并给予赋值
String color, k;
CSet rect1;
rect1=new CSet ( );
System.out.print ('/n请输入颜色:: ');
color=input ( );
System.out.print ('请输入宽度:: ');
k=input ( );
w=Integer.parseInt (k);
System.out.print ('请输入高度:: ');
k=input( );
h=Integer.parseInt (k);
(2)//设置长方形的颜色
(3)//设置长方形的宽、高
rectl.show ( );
(4)//设置长方形的颜色和宽、高
rectl.show ( );
}
[代码6-3]
public static String input( ) throws IOException//输入函数
{
String str;
BufferedReader buf;
(5)
str=buf.readLine ( )
return str;
}
}

A.io.*;
B.out.println
C.out.println
D.out.print
E.out.print
F.parseInt
G.out.print
H.parseInt
I.show
J.show
K.readLine

【参考答案】

(1)pfivate String col;(2)rectl.set(color);(3)rectl.set(wh);(......

(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)
热门 试题

未分类题
阅读以下说明和Visual Basic代码,填入(n)处。[说明]在一些财务软件中,经常需要将阿拉伯数字的账目转化为汉语习惯中的金额计数方法,例如:“3.45”转化为“叁元四角五分”;“3.4”转化为“叁元四角”;“3.40”转化为“叁元四角零分”;“3.456”转化为“叁元四角五分”;“345.00”转化为“叁百四十五元零角零分”;“345”转化为“叁百四十五元”;以下Visual Basic代码实现了小写金额转换为大写金额。界面如图10-9所示。结合实际例子说明,仔细阅读下面代码,将(n)代码补充完整。[代码7-1]Begin VB.FormForm1Caption = '小写金额转换为大写金额' ...窗体描述(略)Begin VB.CommandButton Command1Caption = '退出' ...窗体描述(略)EndBegin VB.TextBox Text2 ...窗体描述(略)EndBegin VB.TextBox Text1Enabled = 0 'False …窗体描述(略)EndBegin VB.Labe1 Labe12Caption = '转换为大写金额' ...窗体描述(略)EndBegin VB.Labe1 Labe11Caphon = '请输入数字' ...窗体描述(略)EndEnd[代码7-2]Private Function setdata (num As Integer) As String '数字转换Select CaSe numCase 0setdata='零'Case 1Setdata='壹'Case 2Setdata='贰'Case 3Setdata='叁'Case4Setdata='肆'Case 5Setdata='伍'Case 6Setdata='陆'Case 7Setdata='柒'Case 8Setdata='捌'Case 9Setdata='玖'End SelectEnd FunctionPrivate Function chang (aaa As Integer) As String '位数转换Select CaSe aaaCase 1chang=''Case 2chang='十'Case 3chang='百'Case 4chang='千'Case 5chang='万'Case 6chang='十'Case 7chang='百'Case 8chang='千'Case 9chang='亿'Case 10chang='十'End SelectEnd Function[代码7-3]Private Sub Text2_Change ( ) '小写转大写Dim i As IntegerDim j As IntegerDim myint As IntegerDim myint1 As IntegerDim mydoub As DoubleDim mystr As StringDim mystr1 As StringDim mystr2 As StringDim mystr3 As StringDim mystr4 As StringDim money As LongDim money1 As IntegerDim money2 As Longmystr=Text2.Textmyint=InStr (mystr, '.')If myint=0 Thenmystr=Text2.TextElsemystr3=Right(Text2.Text, Len (Text2.Text ) - myint)If mystr3<>''Then '转换小数位mystr4=Left(mystr3, 1)mystr3=Right(mystr3, Len(mystr3 )