Java中的难题,哪位高手帮忙解决一下

Java中的难题,哪位高手帮忙解决一下,第1张

这是我以前写过的程序,和你那个挺像,名字什么的你自己改改就好。

class Circle extends Shape {

final double PI_VALUE = 314;

double radius;

Circle(double radius) {

thisradius = radius;

}

Circle() {

}

double area() {

return PI_VALUE thisradius thisradius;

}

}

class Square extends Shape {

double length;

Square(double length) {

thislength = length;

}

Square() {

}

double area() {

return thislength thislength;

}

}

public class ShowArea {

public static void main(String[] args) {

Shape objCircle = new Circle(2);

Systemoutprintln("圆的面积为" + objCirclearea());

Shape objSquare = new Square(2);

Systemoutprintln("正方形的面积为" + objSquarearea());

}

}

你这个程序的语法完全错了,我给你改了一下

BCB不支持内部类的,所以不能在一个过程里声明类

而且for语句的结构也不对

//---------------------------------------------------------------------------

#include <vclh>

#pragma hdrstop

#include "Unit1h"

//---------------------------------------------------------------------------

#pragma package(smart_init)

#pragma resource "dfm"

TForm1 Form1;

//---------------------------------------------------------------------------

__fastcall TForm1::TForm1(TComponent Owner)

: TForm(Owner)

{

}

class fly_shape

{

private :

int x;

int y;

int speed;

int status;

TShape obj;

public:

fly_shape(TComponentAOwner,int x1,int y1,int sp):x(x1),y(y1),speed(sp)

{

obj=new TShape(AOwner);

obj->Left=x;

obj->Top=y;

obj->Width=30;

obj->Height=30;

if(sp>30)

{

obj->Brush->Color=clPurple;

}

else

{

obj->Shape=stCircle;

status=0;

}

}

void active()

{

status=1;

obj->Parent=Form1;

}

void move()

{

if(status==1)

{

obj->Top-=speed;

if(obj->Top<0)

{

obj->Top=y;

}

}

}

};

//---------------------------------------------------------------------------

fly_shape obj1[20];

void __fastcall TForm1::FormActivate(TObject Sender)

{

randomize();

for(int i=0;i<20;i++)

{

obj1[i]=new fly_shape(Form1,150+random(250),300,random(40)+10);

}

}

//---------------------------------------------------------------------------

int count=0;

void __fastcall TForm1::Timer1Timer(TObject Sender)

{

if(count<20)

{

obj1[count]->active();

count++;

}

for(int i=0;i<20;i++)

{

obj1[i]->move();

}

}

//---------------------------------------------------------------------------

obj没有3d的特性。Shapr3D于2016年3月在AppStore上线,是一款直接3D建模工具。obj文件是3D模型文件格式,没有动画、材质特性、贴图路径、动力学、粒子等特性。由Alias|Wavefront公司为3D建模和动画软件AdvancedVisualizer开发,适合用于3D软件模型之间的互导,也可以通过Maya读写。

GetType()就可以,举个例子

List<T> lst=new List<T>();

object obj=lst;

//获取obj类型

SystemType otype = objGetType();

otype就是你需要的原来的类型了。

额,objGetType();应该获得的是List[T的类型],你可以通过类型名称抽取出T的类型再强制转换就可以了。或者直接对list的成员获取类型。

一、取值方法:

String sqlStr = "";

String abcString="4,开,1,222,222,CJ:5,开,1,333,333,CJ:6,开,1,444,444,CJ:24,开,1,999,999,KZ:25,开,1,888,888,KZ";

String[] obj1 = abcStringsplit(":");

for(int i=0; i<obj1length;i++){

Object[] obj2 = obj1[i]split(",");

sqlStr = "insert into xxxtable(param1,param2,param3,param4,param5,param6) values("+obj2[0]+","+obj2[1]+","+obj2[2]+","+obj2[3]+","+obj2[4]+","+obj2[5]+");";

Systemoutprintln(sqlStr);}

二、OBKECT的简单介绍:

软件对象实际上是现实世界对象的造型,因为它同样有状态和行为。一个软件对象利用一个或者多个变量来维持它的状态。变量是由用户标识符来命名的数据项。软件对象用它的方法来执行它的行为。方法是跟对象有关联的函数(子程序)。

对象是理解面向对象技术的关键。用户在学习之前可以看看现实生活中的对象,比如狗、桌子、电视、自行车等等。用户可以发现现实世界中的对象有两个共同特征:它们都有状态和行为。比如狗有自己的状态(比如名字、颜色、生育以及饥饿等等)和行为(比如摇尾巴等等)。同样自行车也有自己的状态(比如当前档位、两个轮子等等)和行为(比如刹车、加速、减速以及改变档位等等)。

/

The Class PerimeterArea This Class is to compute perimeter and area

/

public class PerimeterArea {

/

The main method

@param args

the arguments

/

public static void main(String[] args) {

Shape TriangleObj = new Triangle(3, 4, 5);// 定义三边为3,4,5的三角形

Shape RectangleObj = new Rectangle(5, 6);// 定义长为5,宽为6的矩形

Shape CircleObj = new Circle(5);// 定义半径为5的对象

// 打印各个形状的周长和面积

Systemoutprintln(TriangleObjtoString());

Systemoutprintln(RectangleObjtoString());

Systemoutprintln(CircleObjtoString());

}

}

// 周长接口

interface perimeter {

public abstract double cutePerimeter();

}

// 面积接口

interface area {

public abstract double cuteArea();

}

// 抽象形状类

abstract class Shape implements perimeter, area {

public abstract double cutePerimeter();

public abstract double cuteArea();

}

// 三角形

class Triangle extends Shape {

private int aSide;

private int bSide;

private int cSide;

public Triangle(){}

public Triangle(int aSide, int bSide, int cSide) {

thisaSide = aSide;

thisbSide = bSide;

thiscSide = cSide;

}

public double cutePerimeter() {

return aSide + bSide + cSide;

}

public double cuteArea() {

//面积公式

/设三边长分别为A、B、C,面积为S;周长的一半P为(A+B+C)/2

S=√[P(P-A)(P-B)(P-C)]

√为开二次方 /

int x = (aSide + bSide + cSide) / 2;

return Mathsqrt(x(x-aSide)(x-bSide)(x-cSide));

}

public int getASide() {

return aSide;

}

public void setASide(int side) {

aSide = side;

}

public int getBSide() {

return bSide;

}

public void setBSide(int side) {

bSide = side;

}

public int getCSide() {

return cSide;

}

public void setCSide(int side) {

cSide = side;

}

public String toString() {

return "三角形的周长为:" + cutePerimeter() + "\n三角形的面积为:" + cuteArea() + "\n";

}

}

// 矩形

class Rectangle extends Shape {

private int longLength;

private int widthLength;

public Rectangle(){}

public Rectangle(int longLength, int widthLength) {

thislongLength = longLength;

thiswidthLength = widthLength;

}

public double cutePerimeter() {

return 2 (longLength + widthLength);

}

public double cuteArea() {

return longLength widthLength;

}

public int getLongLength() {

return longLength;

}

public void setLongLength(int longLength) {

thislongLength = longLength;

}

public int getWidthLength() {

return widthLength;

}

public void setWidthLength(int widthLength) {

thiswidthLength = widthLength;

}

public String toString() {

return "矩形的周长为:" + cutePerimeter() + "\n矩形的面积为:" + cuteArea() + "\n";

}

}

// 圆形

class Circle extends Shape {

public final double pi = 314;

private double radius;

public Circle(){}

public Circle(double radius) {

thisradius = radius;

}

public double cutePerimeter() {

return 2 pi radius;

}

public double cuteArea() {

return pi radius radius;

}

public double getRadius() {

return radius;

}

public void setRadius(double radius) {

thisradius = radius;

}

public String toString() {

return "圆形的周长为:" + cutePerimeter() + "\n圆形的面积为:" + cuteArea() + "\n";

}

}

三角形面积已经修正~谢谢楼上的兄弟~set和get方法只是为了拓展性考虑~不局限于new才能设置参数值

以上就是关于Java中的难题,哪位高手帮忙解决一下全部的内容,包括:Java中的难题,哪位高手帮忙解决一下、一个C++builder程序问题多多,但不知错在哪里啊!!、shape3d不支持obj等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

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

原文地址: https://outofmemory.cn/web/9411108.html

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

发表评论

登录后才能评论

评论列表(0条)

保存