精华内容
下载资源
问答
  • Java:计算立方体的体积和底面积
    2021-10-05 21:04:56
    
    package org.demo;
     
    public class Rect {
    	//定义矩形长和宽
    	private double l,w;
    	Rect(double c,double k){
    		l=c;
    		w=k;
    	}
    	//矩形面积
    	public double s(){
    		return w*l;
    	}
    class Cube extends Rect {
    	private double h;
     
    	Cube(double c, double k,double g) {
    		// TODO Auto-generated constructor stub
    		super(c, k);
    		h=g;
    	}
    	//计算立方体体积
    	public double v(){
    		return s()*h;
    	}
    //测试类
    public void main(String[] args) {
    		Cube cube=new Cube(5, 6,7);
    	    System.out.println("底面积为:"+cube.s());
    	    System.out.println("体积为:"+cube.v());
    	}
    }
    }

    更多相关内容
  • 下载一个官方3D插件:JAVA 3D API 最新j3d-1_5_2-windows-i586.exehttps://java3d.dev.安装成功就可以运行以下程序// JFrameimport javax.swing.JFrame;// BorderLayout stuffimport java.awt.*;import javax.swing....

    下载一个官方3D插件:

    JAVA 3D API 最新j3d-1_5_2-windows-i586.exe

    https://java3d.dev.

    安装成功就可以运行以下程序

    // JFrame

    import javax.swing.JFrame;

    // BorderLayout stuff

    import java.awt.*;

    import javax.swing.*;

    // Canvas3D

    import javax.media.j3d.Canvas3D;

    // The Universe

    import com.sun.j3d.utils.universe.SimpleUniverse;

    // The BranchGroup

    import javax.media.j3d.BranchGroup;

    // For the Box

    import com.sun.j3d.utils.geometry.Box;

    import javax.vecmath.*;

    // The directional light

    import javax.media.j3d.DirectionalLight;

    // For the bouding sphere of the light source

    import javax.media.j3d.BoundingSphere;

    import javax.media.j3d.Appearance;

    import javax.media.j3d.Material;

    // Transformgroup

    import javax.media.j3d.TransformGroup;

    import com.sun.j3d.utils.behaviors.mouse.*;

    public class BasicConstruct extends JFrame

    {

    /**

    * The SimpleUniverse object

    */

    protected SimpleUniverse simpleU;

    /**

    * The root BranchGroup Object.

    */

    protected BranchGroup rootBranchGroup;

    /**

    * Constructor that consturcts the window with the given

    * name.

    *

    * @param name The name of the window, in String format

    */

    public BasicConstruct(String name)

    {

    // The next line will construct the window and name it

    // with the given name

    super(name);

    // Perform the initial setup, just once

    initial_setup();

    }

    /**

    * Perform the essential setups for the Java3D

    */

    protected void initial_setup()

    {

    // A JFrame is a Container -- something that can hold

    // other things, e.g a button, a textfield, etc..

    // however, for a container to hold something, you need

    // to specify the layout of the storage. For our

    // example, we would like to use a BorderLayout.

    // The next line does just this:

    getContentPane().setLayout(new BorderLayout());

    // The next step is to setup graphics configuration

    // for Java3D. Since different machines/OS have differnt

    // configuration for displaying stuff, therefore, for

    // java3D to work, it is important to obtain the correct

    // graphics configuration first.

    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    // Since we are doing stuff via java3D -- meaning we

    // cannot write pixels directly to the screen, we need

    // to construct a "canvas" for java3D to "paint". And

    // this "canvas" will be constructed with the graphics

    // information we just obtained.

    Canvas3D canvas3D = new Canvas3D(config);

    // And we need to add the "canvas to the centre of our

    // window..

    getContentPane().add("Center", canvas3D);

    // Creates the universe

    simpleU = new SimpleUniverse(canvas3D);

    // First create the BranchGroup object

    rootBranchGroup = new BranchGroup();

    }

    /**

    * Adds a light source to the universe

    *

    * @param    direction The inverse direction of the

    *                    light

    * @param    color        The color of the light

    */

    public void addDirectionalLight(Vector3f direction, Color3f color)

    {

    // Creates a bounding sphere for the lights

    BoundingSphere bounds = new BoundingSphere();

    bounds.setRadius(1000d);

    // Then create a directional light with the given

    // direction and color

    DirectionalLight lightD = new DirectionalLight(color, direction);

    lightD.setInfluencingBounds(bounds);

    // Then add it to the root BranchGroup

    rootBranchGroup.addChild(lightD);

    }

    /**

    * Adds a box to the universe

    *

    * @param    x    The x dimension of the box

    * @param    y    The y dimension of the box

    * @param    z    The z dimension of the box

    */

    public void addBox(float x, float y, float z, Color3f diffuse, Color3f spec)

    {

    // Add a box with the given dimension

    // First setup an appearance for the box

    Appearance app = new Appearance();

    Material mat = new Material();

    mat.setDiffuseColor(diffuse);

    mat.setSpecularColor(spec);

    mat.setShininess(5.0f);

    app.setMaterial(mat);

    Box box = new Box(x, y, z, app);

    // Create a TransformGroup and make it the parent of the box

    TransformGroup tg = new TransformGroup();

    tg.addChild(box);

    // Then add it to the rootBranchGroup

    rootBranchGroup.addChild(tg);

    tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    MouseRotate myMouseRotate = new MouseRotate();

    myMouseRotate.setTransformGroup(tg);

    myMouseRotate.setSchedulingBounds(new BoundingSphere());

    rootBranchGroup.addChild(myMouseRotate);

    MouseTranslate myMouseTranslate = new MouseTranslate();

    myMouseTranslate.setTransformGroup(tg);

    myMouseTranslate.setSchedulingBounds(new BoundingSphere());

    rootBranchGroup.addChild(myMouseTranslate);

    MouseZoom myMouseZoom = new MouseZoom();

    myMouseZoom.setTransformGroup(tg);

    myMouseZoom.setSchedulingBounds(new BoundingSphere());

    rootBranchGroup.addChild(myMouseZoom);

    }

    /**

    * Finalise everything to get ready

    */

    public void finalise()

    {

    // Then add the branch group into the Universe

    simpleU.addBranchGraph(rootBranchGroup);

    // And set up the camera position

    simpleU.getViewingPlatform().setNominalViewingTransform();

    }

    public static void main(String[] argv)

    {

    BasicConstruct bc = new BasicConstruct("Foo");

    bc.setSize(250, 250);

    bc.addBox(0.4f, 0.5f, 0.6f, new Color3f(1, 0, 0), new Color3f(1, 0, 0));

    bc.addDirectionalLight(new Vector3f(0f, 0f, -1),

    new Color3f(1f, 1f, 0f));

    bc.finalise();

    bc.show();

    return;

    }

    }

    [本帖最后由 lampeter123 于 2009-11-9 09:48 编辑]

    6f83fddf9cb9ff6843fffd45e1807199.gif

    你的优秀和我的人生无关!!!!

    我要过的,是属于我自己的生活~~~

    展开全文
  • java计算立方体体积(利用类函数)

    千次阅读 2020-04-06 23:07:42
    包名展示 直接上代码 package volume; import java.util.Scanner; public class volume { ... public static void main...//输入立方体的长宽高信息 Scanner sc = new Scanner(System.in); System.out.println("--...

    包名展示
    在这里插入图片描述
    直接上代码

    package volume;
    
    import java.util.Scanner;
    
    public class volume {
    
        public static void main(String[] args) {
    
    //输入立方体的长宽高信息
    	Scanner sc = new Scanner(System.in);
    	System.out.println("---------计算立方体的体积---------");
    	variable v = new variable();
    	System.out.println("请输入立方体的长:");
    	int a = sc.nextInt();
    	System.out.println("请输入立方体的宽:");
    	int b = sc.nextInt();
    	System.out.println("请输入立方体的高:");
    	int c = sc.nextInt();
    //	set调用
    	v.seta(a);
    	v.setb(b);
    	v.setc(c);
    	v.show();
    //	调用vol方法计算体积并输出
    	vol(a, b, c);
        }
    
        public static void vol(int a,int b,int c){
    	System.out.println("其体积为:"+(a*b*c));
        }
    }
    
    
    package volume;
    //定义类
        public class variable {
                private int a;
                private int b;
                private int c;
    //         无参方法   
            public variable(){
        	
            }
    //         带参方法
            public variable(int a,int b,int c){
            	this.a = a;
            	this.b = b;
            	this.c = c;
            }
    //        set get方法
            public void seta(int a){
        		this.a = a;
            }
            public int geta(){
        		return a;
            }
            public void setb(int b){
        		this.b = b;
            }
            public int getb(){
        		return b;
            }
            public void setc(int c){
        		this.c = c;
            }
            public int getc(){
        		return c;
            }
    //        输出立方体的信息
            public void show() {
        		System.out.println("您输入的立方体长为:"+a+",宽为:"+b+",高为:"+c);
        	
            }
    }
    

    代码运行结果展示
    在这里插入图片描述

    展开全文
  • Java3D 正方体

    2021-03-21 09:57:24
    一个最简单的Java3D的例子。import java.applet.Applet;import java.awt.BorderLayout;import java.awt.GraphicsConfiguration;import javax.media.j3d.Alpha;import javax.media.j3d.BoundingSphere;import javax....

    一个最简单的Java3D的例子。

    import java.applet.Applet;

    import java.awt.BorderLayout;

    import java.awt.GraphicsConfiguration;

    import javax.media.j3d.Alpha;

    import javax.media.j3d.BoundingSphere;

    import javax.media.j3d.BranchGroup;

    import javax.media.j3d.Canvas3D;

    import javax.media.j3d.RotationInterpolator;

    import javax.media.j3d.Transform3D;

    import javax.media.j3d.TransformGroup;

    import javax.vecmath.Point3d;

    import com.sun.j3d.utils.applet.MainFrame;

    import com.sun.j3d.utils.geometry.ColorCube;

    import com.sun.j3d.utils.universe.SimpleUniverse;

    public class HelloUniverse extends Applet {

    private static final long serialVersionUID = 41293118815177506L;

    private SimpleUniverse u = null;

    public BranchGroup createSceneGraph() {

    BranchGroup objRoot = new BranchGroup();

    TransformGroup objTrans = new TransformGroup();

    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    objRoot.addChild(objTrans);

    // 创建一个3D对象,正方体

    objTrans.addChild(new ColorCube(0.4));

    Transform3D yAxis = new Transform3D();

    Alpha rotationAlpha = new Alpha(-1, 6000);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha,

    objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0),

    100.0);

    rotator.setSchedulingBounds(bounds);

    objRoot.addChild(rotator);

    objRoot.compile();

    return objRoot;

    }

    public HelloUniverse() {

    }

    public void init() {

    setLayout(new BorderLayout());

    GraphicsConfiguration config = SimpleUniverse

    .getPreferredConfiguration();

    Canvas3D c = new Canvas3D(config);

    add("Center", c);

    BranchGroup scene = createSceneGraph();

    u = new SimpleUniverse(c);

    u.getViewingPlatform().setNominalViewingTransform();

    u.addBranchGraph(scene);

    }

    public void destroy() {

    u.cleanup();

    }

    public static void main(String[] args) {

    new MainFrame(new HelloUniverse(), 512, 512);

    }

    }

    展开全文
  • 追答:下面的Cube类和Test类是回答你的两个问题,要放在相对应的不同.java文件中分别编译,用Test类运行。就是说Square和Cube类可以放在Cube.java中,Test类放在Test.java中分别编译。 class Square{ double w=0; ...
  • FarmingTime Limit: 12000/6000 MS (Java/Others)Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1375Accepted Submission(s): 402Problem DescriptionYou have a big farm, and you want ...
  • Java学习 之 画图板 立方体

    千次阅读 2019-09-16 18:21:13
    Java学习 之 画图板 立方体步骤画小立方体画3 *3 *3的立方体递归画出更大的立方体 步骤 1、先画一个小立方体,三个面填充不一样的颜色 2、再由小立方体搭成一个3 * 3 * 3的立方体 3、以上图立方体为最小单位,...
  • package *;.../*** @program: simple_tools* @description: 立方体操作工具类* @author: ChenWenLong* @create: 2019-06-03 16:58**/public class CuboidUtils {public static final DecimalFor...
  • 实验室二 Java实验二-正方形和立方体
  • 研究了很久的java3d,从昨天开始研究怎么加载纹理,今天终于搞定。原本想用数组加载图片,但是总是ava.lang.NullPointerException。于是就放弃了一个个加载。。有点傻~本人rookie,高手路过多提携。。。importjava....
  • MiniCubes MiniCubes是一个轻量级、高性能、分布式、内存型...Java8 Nashorn:使用Nashorn引擎在索引构建阶段加入自定义扩展功能,可提供原始数据中没有的维度列,增强查询能力。 JavaFX 8:使用JavaFX构建客户端软件,
  • 描述小Hi在水平桌面上放置了一个立方体。初始时,上下左右前后6个面的编号依次是1、6、4、3、2、5。现在立方体经过若干次翻滚,每次翻滚是向前翻滚90度(F)、向后翻滚90度(B)、向左翻滚90度(L)、向右翻滚90度(R)之一...
  • TrivialCube 可以使用 sum 或 count 聚合函数计算完整或部分立方体。 输入文件最多必须有 9 列 必需的 Java Maven (在 debian/ubuntu 中安装 maven: sudo apt-get install maven2 ) 安装 git 克隆 cd ...
  • 关键词:Java3d,正方体在运行程序的时候,请确保你已经安装了Java的3D工具包,否则是无法编译通过的。如果要下载Java3D的api可以点下面的连接:...
  • import java.awt.*;import java.awt.event.*;public class Volume extends JFrame implements ActionListener,ItemListener{JPanel p1,p2,p3;JRadioButton rb1,rb2,rb3;ButtonGroup bg;JButton...
  • 使用Graphics2D类draw方法绘制立方体 运行示例: 源码: 1. 实体类 import java.awt.Graphics2D; import java.awt.Polygon; import java.awt.geom.GeneralPath; import java.security.SecureRandom; ...
  • 下面的Cube类和Test类是回答你的两个问题,要放在相对应的不同.java文件中分别编译,用Test类运行。就是说Square和Cube类可以放在Cube.java中,Test类放在Test.java中分别编译。 class Square{ double w=0; double l...
  • [JAVA]计算底面为正方形的长方体体积要求函数需求Java中自带的数学方法计算平方1--10的随机数计算出的结果向上取整代码实现 要求 1.底面正方形输入数据为浮点型数据,底面积需使用Java中自带的数学方法计算平方; 2....
  • 设计一个立方体类BOX,它能计算并输出立方体的体积和表面积答:#include\nusing namespace std;\nclass BOX\n{\nprivate:\nint length;\npublic:\nvoid setLength(int len ){//设置正方体边长\nif(len > 0){\n...
  • 教程中的一个小例子,使用java3d的api编写的一个小程序,建立一个立方体
  • I've created a small piece of code which draws a 3D cube in my SWT application allowing to rotate it.Now, I want to change each face/side of the cube and draw a different image on it, but I can't find...
  • 1.创建图形,图形包括圆形,矩形,立方体,圆柱 2.对于各个图形均可求得面积与周长 3.可以浏览目前所有已经存在的图形与其信息 4.退出系统 主基类 shape类: package System2; public class shape {
  • (4)功能方法包括计算表面积getArea()、计算体积getCubage()、判断是否正方体isCube()、输出该长方体的长宽高printCuboid()、绘制该长方体(给出提示信息即可)drawing()。测试一要求如下:(1)利用空构造方法创建一...
  • 用于控制 LED 立方体的高级 GUI 要求 加工 ControlP5 库 信息 这是一个以 3D 形式显示立方体并允许手动创建动画的 GUI。 你也可以用它玩蛇 3D :D GUI 可以与任何尺寸的 LED 立方体配合使用,但串行通信仅适用于 8...
  • 一、建立坐标系1)立方体坐标系我们以立方体的几何中心作为原点,如图建立坐标系。2)canvas坐标系canvas坐标系主要用于显示3维平面在浏览器中的投影(就像一束光照射在立方体上,在墙面出现的阴影)。三维坐标系的层次...
  • Java语言实现鼠标拖动旋转立方体 Java语言实现鼠标拖动旋转立方体 Java语言实现鼠标拖动旋转立方体 Java语言实现鼠标拖动旋转立方体
  • primaryStage.setTitle("立方体"); primaryStage.show(); } private Pane getPane() { BorderPane pane = new BorderPane(); Group group = new Group(); //组 Polygon up = new Polygon(15, 30, 100, 30, 90, 50, ...
  • CSS3 3D旋转立方体

    2021-03-14 04:16:50
    主要用到动画css3 animation,特别注意当完成正方体的过程中,每个面旋转时这个面的坐标系是跟着变换的,只是他们的相对位置不变,默认的变换基点是(50% 50% 0),我们可以使用transform-origin改变默认基点,也可以按...
  • 给出立方体六个面,合成一张全景图 二、主要知识:py360convert 2.1、该项目的特点: 立方体贴图和等矩形之间的转换 等角于平面 纯python实现,仅依赖于numpy和scipy 矢量化实施(在大多数...
  • 共回答了20个问题采纳率:100%public class Cube {private int length;private int width ;private int height;public Cube(int length, int width, int height) {super();this.length = length;...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 10,026
精华内容 4,010
关键字:

java立方体

java 订阅