用java设计一个长方形类,成员变量包括长和宽.方法:计算面积和周长,有相应的set和get方法

用java设计一个长方形类,成员变量包括长和宽.方法:计算面积和周长,有相应的set和get方法,第1张

/
长方形
/
class Rectangle{
/

/
private double width;
/

/
private double height;

/
构造方法
@param width 宽
@param height 高
/
public Rectangle(double width, double height){
thiswidth = width;
thisheight = height;
}

/
计算长方形的面积
@return 返回长方形的面积
/
public double getArea(){
return thiswidth thisheight;
}

/
计算长方形的周长
@return 返回长方形的周长
/
public double getGirth(){
return 2 (thiswidth + thisheight);
}

public double getWidth(){
return thiswidth;
}

public void setWidth(double width){
thiswidth = width;
}

public double getHeight(){
return thisheight;
}

public void setHeight(double height){
thisheight = height;
}
}
public class Test {
public static void main(String[] args){
Rectangle rect = new Rectangle(2,3);
Systemoutprintln("长方形的宽 :" + rectgetWidth());
Systemoutprintln("长方形的高 :" + rectgetHeight());
Systemoutprintln("长方形的面积:" + rectgetArea());
Systemoutprintln("长方形的周长:" + rectgetGirth());
}
}

public class Rect {
private double len;
private double width;
private double height;
//体积
public double volume () {
return thislen thiswidth thisheight;
}
public double getLen() {
return len;
}
public void setLen(double len) {
thislen = len;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
thiswidth = width;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
thisheight = height;
}
}
class RectTest {
public static void main(String[] args) {
Rect rect = new Rect();
rectsetLen(5);
rectsetWidth(7);
rectsetHeight(9);
double volume = rectvolume();
Systemoutprintln("体积为 = " + volume);
}
}

我是个程序白痴,只能用网上找到的一个教程来给你看看了
如果感觉能找到希望采纳
CENTER 中心点(屏幕中心)如("CENTER", -220, -260) 就是以屏幕中心点为基准窗体偏移量的一个设置!
TOPLEFT 屏幕左上
TOPRIGHT 屏幕右上
BOTTOMLEFT 屏幕左下
BOTTOMRIGHT 屏幕右下! 先区分你要修改的窗体位置。然后搞明白你要修改到何处!
偏移量 0(横向), 0(纵向)
如:player:SetPoint("CENTER", -220, -260)
玩家窗体窗体为屏幕中心点横向-220 纵向-260处。
pettarget:SetPoint("TOPRIGHT", player, "BOTTOMRIGHT", 0, -20
窗体跟随 此句的意思表达为 宠物窗体 跟随玩家窗体 位置在玩家窗体右下方 0 -20 是以玩家窗体的为基准的一个偏移量!如我修改的焦点,原版是不跟随的,但我修改为
focus:SetPoint("TOPLEFT", player, "TOPLEFT", 0, 50) 就变成了焦点跟随玩家窗体左上方
-- Spawn the frames we want
local player = oUF:Spawn"player"
player:SetPoint("CENTER", -220, -260) 玩家窗体设置!
player:SetHeight(30) 高度
player:SetWidth(220)宽度
local target = oUF:Spawn"target"
target:SetPoint("CENTER", 220, -260) 目标窗体
target:SetHeight(30)
target:SetWidth(220)
local pet = oUF:Spawn"pet"
pet:SetPoint("TOPLEFT", player, "BOTTOMLEFT", 0, -20) 宠物窗体
pet:SetHeight(22)
pet:SetWidth(145)
local pettarget = oUF:Spawn"pettarget"
pettarget:SetPoint("TOPRIGHT", player, "BOTTOMRIGHT", 0, -20) 宠物目标
pettarget:SetHeight(22)
pettarget:SetWidth(145)
local tot = oUF:Spawn"targettarget"
tot:SetPoint("CENTER", 0, -260) 目标的目标
tot:SetHeight(10)
tot:SetWidth(160)
local focus = oUF:Spawn"focus" 焦点
focus:SetPoint("TOPLEFT", player, "TOPLEFT", 0, 50)
focus:SetHeight(10)
focus:SetWidth(140)
----------------------------
队友设置
----------------------------
local party = oUF:Spawn("party")
party:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 15, -200) 偏移量 及位置信息
party:SetManyAttributes("showParty", true, "yOffset", -50) 间距及延伸方向 是否显示小队
party:SetAttribute("showRaid", false)将团队显示与小队显示在一块即true为团队时在小队后面递增添加团队模块false只显示小队不显示团队!
local party1target = oUF:Spawn("party1target") 队伍1 目标 以下,2 3 4
party1target:SetPoint("LEFT", oUF_PartyUnitButton1, "RIGHT", 10, 1)
party1target:SetHeight(10)
party1target:SetWidth(80)
local party2target = oUF:Spawn("party2target")
party2target:SetPoint("LEFT", oUF_PartyUnitButton1, "RIGHT", 10, -76)
party2target:SetHeight(10)
party2target:SetWidth(80)
local party3target = oUF:Spawn("party3target")
party3target:SetPoint("LEFT", oUF_PartyUnitButton1, "RIGHT", 10, -151)
party3target:SetHeight(10)
party3target:SetWidth(80)
local party4target = oUF:Spawn("party4target")
party4target:SetPoint("LEFT", oUF_PartyUnitButton1, "RIGHT", 10, -226)
party4target:SetHeight(10)
party4target:SetWidth(80)
就是死性不改 提供的一些代码。。。同志们一起感谢!
为OUF的自己和目标加3D头像,打开layoutlua,在最后加上这段代码:
--2D头像
local portrait = self:CreateTexture(nil, "OVERLAY")
portraittype = "2D"
portrait:SetTexCoord(014644660941, 085355339059, 014644660941, 085355339059)
portrait:SetWidth(35) -- 头像的宽度
portrait:SetHeight(35) -- 头像的高度
if (unit == "target") then --- 这里是需要在右边加头像的框体
portrait:SetPoint("RIGHT", 36, 0) --头像的位置
elseif (unit == "player" or self:GetParent():GetName() == "oUF_Party") then -- 这里是需要在左边加头像的框体
portrait:SetPoint("LEFT", -36, 0) -- 头像的位置
end
selfPortrait = portrait
--3D头像
local portrait = CreateFrame("PlayerModel", nil, self)
portrait:SetFrameStrata"MEDIUM"
portraittype = "3D"
portrait:SetLight(1, 0, 0, -0707, -0707, 07, 10, 10, 10, 08, 10, 10, 08)
portrait:SetWidth(35) -- 高
portrait:SetHeight(35) -- 宽
if (unit == "target") then --- 这里是需要在右边加头像的框体
portrait:SetPoint("RIGHT", 36, 0) --位置
elseif (unit == "player" or self:GetParent():GetName() == "oUF_Party") then -- 这里是需要在左边加头像的框体
portrait:SetPoint("LEFT", -36, 0) -- 位置
end
selfPortrait = portrait
--头像背景设置
local portraitbg = portrait:CreateTexture(nil, "BORDER")
portraitbg:SetAllPoints(portrait)
portraitbg:SetTexture(tex)
portraitbg:SetTexture(0, 0, 0, 1)
------------------------ 我是传说中的分割线 ----------------------
或者都复制进去,加上一个判断,需要2D或者3D修改一个字就行了,代码如下:
-- 加入头像判断 ---
local viewtype = "2D" -- 2D - 头像显示为2D模式,3D - 头像为3D模式
-- 3D模式
if viewtype == "3D" then
local portrait = CreateFrame("PlayerModel", nil, self)
portrait:SetFrameStrata"MEDIUM"
portraittype = "3D"
portrait:SetLight(1, 0, 0, -0707, -0707, 07, 10, 10, 10, 08, 10, 10, 08)
portrait:SetWidth(40)
portrait:SetHeight(40)
if (unit == "target") then
portrait:SetPoint("RIGHT", 40, 0)
elseif (unit == "player" or unit == "pet" or unit == "focus" or self:GetParent():GetName() == "oUF_Party") then -- 比上面的代码多了宠物的头像
portrait:SetPoint("LEFT", -40, 0)
end
selfPortrait = portrait
--头像背景
local portraitbg = portrait:CreateTexture(nil, "BORDER")
portraitbg:SetAllPoints(portrait)
portraitbg:SetTexture(tex)
portraitbg:SetTexture(0, 0, 0, 1)
-- 2D模式
elseif viewtype == "2D" then
local portrait = self:CreateTexture(nil, "OVERLAY")
portraittype = "2D"
portrait:SetTexCoord(014644660941, 085355339059, 014644660941, 085355339059)
portrait:SetWidth(40)
portrait:SetHeight(40)
if (unit == "target") then
portrait:SetPoint("RIGHT", 40, 0)
elseif (unit == "player" or unit == "pet" or unit == "focus" or self:GetParent():GetName() == "oUF_Party") then -- 比上面的代码多了宠物的头像
portrait:SetPoint("LEFT", -40, 0)
end
selfPortrait = portrait
-- 头像背景
local portraitbg = self:CreateTexture(nil, "BORDER")
portraitbg:SetAllPoints(portrait)
portraitbg:SetTexture(tex)
portraitbg:SetTexture(0, 0, 0, 1)
end
如果想移动头像位置(同时按住SHIFT+ALT 拖动),就加上这段:
DefindedFrames = {
["oUF_Player"] = {isLock = nil},
["oUF_Target"] = {isLock = nil},
["oUF_TargetTarget"] = {isLock = nil},
["oUF_TargetTargetTarget"] = {isLock = nil},
["oUF_Focus"] = {isLock = nil},
["oUF_Focustarget"] = {isLock = nil},
["oUF_Party"] = {isLock = nil},
}
function SetFrameMovable(frameName)
local f = getglobal(frameName);
if f then
if not f:IsMovable() then
f:SetMovable(true);
end
f:RegisterForDrag("LeftButton");
f:SetScript("OnDragStart",function()
if not DefindedFrames[frameName]isLock then
if arg1 == "LeftButton" and IsAltKeyDown() and IsShiftKeyDown() then
this:StartMoving();
end
end
end);
f:SetScript("OnDragStop",function()
this:StopMovingOrSizing();
end);
end
end;
for k,v in pairs(DefindedFrames) do
SetFrameMovable(k);
end
如果想设置头像大小,就加上这段:
local plSize = 1 -- 玩家、宠物、目标、焦点目标、目标的目标、焦点目标的目标的比例
local ptSize = 1 -- 队友、队友宠物、队友目标的比例
oUF_Player:SetScale(plSize);
oUF_Pet:SetScale(plSize);
oUF_Target:SetScale(plSize);
oUF_TargetTarget:SetScale(plSize);
oUF_Focus:SetScale(plSize);
oUF_Focustarget:SetScale(plSize);
oUF_Party:SetScale(plSize);
for i=1, 4 do
getglobal("oUF_Party"i"Target"):SetScale(ptSize);
getglobal("oUF_PartyPet"i):SetScale(ptSize);
end
--------------------------------------------
-- 显示玩家的小队
local updatePartyNum = function(self, event, unit)
if selfunit ~= unit then return end
local RaidPartyNum = selfRaidPartyNum
local numText, name, rank, subgroup;
if ( GetNumRaidMembers() == 0 ) then
numText = " ";
else
local numRaidMembers = GetNumRaidMembers();
for i=1, MAX_RAID_MEMBERS do
if ( i <= numRaidMembers ) then
name, rank, subgroup = GetRaidRosterInfo(i);
-- Set the player's group number indicator
if ( name == UnitName(unit) ) then
numText = " "subgroup"小队";
end
end
end
end
RaidPartyNum:SetText(numText)
RaidPartyNum:SetTextColor(1, 1, 1)
end
if selfRaidPartyNum then
updatePartyNum(self, event, unit)
end
-- 玩家小队的显示位置
local RaidPartyNum
RaidPartyNum = pp:CreateFontString(nil, "OVERLAY")
RaidPartyNum:SetPoint("TOP", portrait, "TOP", 0, 15) -- 我设置的是显示在头像正上方
RaidPartyNum:SetFont(font, fontHeight)
RaidPartyNum:SetShadowColor(0, 0, 0)
RaidPartyNum:SetShadowOffset(08, -08)
selfRaidPartyNum = RaidPartyNum

#include<stdioh>

class Rectangle

{

public:

double Length;//长度

double Width;//宽度

Rectangle(double length, double width) {//定义一个有两个参数的构造函数,用于设置长方形的宽度和长度

this->Length = length;

this->Width = width;

}

double Area() { //求面积函数

return Width Length;//返回长度和宽度的乘积

}

};

class Rectangular :Rectangle

{

public:

double Height;

Rectangular(double length, double width, double height) :Rectangle(length, width) {//定义一个有三个参数的构造函数,用于设置立方体的宽度和长度以及高度

this->Height = height;

}

double Volume() {//求体积函数

return this->Area() Height;//返回长度和宽度及高度的乘积

}

};

int main() {

Rectangle rect(3, 6);//定义长方体类实例

printf("面积:%lf \n", rectArea());//调用求面积方法并输出结果

Rectangular rguar(5, 10, 3);//定义立方体类实例

printf("体积:%lf", rguarVolume());//调用求体积方法并输出结果

char c;

scanf("%c", &c);//这句是为了防止控制台退出

return 0;

}

public class TestRec{

public static void main(String[] args){

double vol, area = 00;

Rectangle rec = new Rectangle(2, 3);

area = recgetRecArea();

Rectangular recr = new Rectangular();

recrsetLength(2);

recrsetWidth(3);

recrsetHeight(4);

vol = recrgetRecVol();

Systemoutprintln("长方形面积:" + area + ",长方体体积:" + vol);

}

}

扩展资料:

数据成员 m_hDC CDC对象使用的输出设备上下文。

m_hAttribDC CDC对象使用的输出属性上下文。

构造函数 CDC 构造一个CDC对象。

初始化 CreateDC 为指定设备创建设备上下文。

CreateIC 为指定设备创建信息上下文。这提供了一种不创建设备上下文即获取有关设备信息的快速方式。

CreateCompatibleDC 创建内存设备上下文,与另一个设备上下文匹配。可以用它在内存中准备图像。

DeleteDC 删除CDC对象对应的Windows设备上下文。

FromHandle 给定设备上下文句柄时,返回指向CDC对象的指针。如果CDC对象未附加到句柄,则创建并附加一个临时CDC对象。

参考资料来源:百度百科-成员函数


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12893241.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-28
下一篇 2023-05-28

发表评论

登录后才能评论

评论列表(0条)

保存