您的位置:

java程序设计d卷(java程序设计a卷)

本文目录一览:

java程序设计?

下面是BankAccount类的代码:

public class BankAccount {

  private String name;

  private double balance;

  private int year;

  private double rate = 0.01d;

  public String getName() {

      return name;

  }

  public void setName(String name) {

      this.name = name;

  }

  public double getRate() {

      return rate;

  }

  public void setRate(double rate) {

      this.rate = rate;

  }

  public double getBalance() {

      return balance;

  }

  public BankAccount() {

      this.balance = 10d;

      this.year = 1;

  }

  public BankAccount(double balance, int year) {

      this.balance = balance;

      this.year = year;

  }

  public void save(double balance, int year) {

      this.balance = this.balance + balance;

      this.year = year;

  }

  public void fetch(double balance) {

      this.balance = this.balance - balance;

      this.year = 0;

  }

  public double calcTotal() {

      return this.balance * this.rate * this.year + this.balance;

  }

}

下面是BankTest类的代码:

public class BankTest {

  public static void main(String[] args) {

      BankAccount account = new BankAccount(1000d, 3);

      account.setName("Tom");

      account.save(2000d, 3);

      System.out.println("该账户的姓名:" + account.getName());

      System.out.println("该账户的存款额:" + account.getBalance());

      System.out.println("该账户的总金额:" + account.calcTotal());

  }

}

下面是运行结果:

麻烦您看一下,是否能够满足要求。

JAVA初学者编程题d

import java.awt.BorderLayout;

import javax.swing.JPanel;

import javax.swing.JFrame;

import java.awt.Dimension;

import java.awt.GridBagLayout;

import java.awt.GridBagConstraints;

import java.awt.GridLayout;

import javax.swing.JButton;

import java.awt.CardLayout;

public class mianbansy extends JFrame {

private static final long serialVersionUID = 1L;

private JPanel jContentPane = null;

private JPanel jPanel = null;

private JPanel jPanel1 = null;

private JPanel jPanel2 = null;

private JButton jButton = null;

private JButton jButton1 = null;

private JButton jButton2 = null;

private JButton jButton3 = null;

private static mianbansy mbsy;

/**

* This is the default constructor

*/

public mianbansy() {

super();

initialize();

}

/**

* This method initializes this

*

* @return void

*/

private void initialize() {

this.setSize(433, 358);

this.setContentPane(getJContentPane());

this.setTitle("JFrame");

this.setVisible(true);

}

/**

* This method initializes jContentPane

*

* @return javax.swing.JPanel

*/

private JPanel getJContentPane() {

if (jContentPane == null) {

jContentPane = new JPanel();

jContentPane.setLayout(new BorderLayout());

jContentPane.add(getJPanel(), BorderLayout.WEST);

jContentPane.add(getJPanel1(), BorderLayout.EAST);

jContentPane.add(getJPanel2(), BorderLayout.CENTER);

}

return jContentPane;

}

/**

* This method initializes jPanel

*

* @return javax.swing.JPanel

*/

private JPanel getJPanel() {

if (jPanel == null) {

GridLayout gridLayout = new GridLayout();

gridLayout.setRows(1);

jPanel = new JPanel();

jPanel.setLayout(gridLayout);

jPanel.setPreferredSize(new Dimension(200, 0));

jPanel.add(getJButton1(), null);

jPanel.add(getJButton2(), null);

jPanel.add(getJButton(), null);

}

return jPanel;

}

/**

* This method initializes jPanel1

*

* @return javax.swing.JPanel

*/

private JPanel getJPanel1() {

if (jPanel1 == null) {

jPanel1 = new JPanel();

jPanel1.setLayout(new GridBagLayout());

jPanel1.setPreferredSize(new Dimension(100, 0));

}

return jPanel1;

}

/**

* This method initializes jPanel2

*

* @return javax.swing.JPanel

*/

private JPanel getJPanel2() {

if (jPanel2 == null) {

jPanel2 = new JPanel();

jPanel2.setLayout(new CardLayout());

jPanel2.add(getJButton3(), getJButton3().getName());

}

return jPanel2;

}

/**

* This method initializes jButton

*

* @return javax.swing.JButton

*/

private JButton getJButton() {

if (jButton == null) {

jButton = new JButton();

jButton.setText("1");

}

return jButton;

}

/**

* This method initializes jButton1

*

* @return javax.swing.JButton

*/

private JButton getJButton1() {

if (jButton1 == null) {

jButton1 = new JButton();

jButton1.setText("3");

}

return jButton1;

}

/**

* This method initializes jButton2

*

* @return javax.swing.JButton

*/

private JButton getJButton2() {

if (jButton2 == null) {

jButton2 = new JButton();

jButton2.setText("2");

}

return jButton2;

}

/**

* This method initializes jButton3

*

* @return javax.swing.JButton

*/

private JButton getJButton3() {

if (jButton3 == null) {

jButton3 = new JButton();

jButton3.setName("jButton3");

jButton3.setText("center面板按钮");

}

return jButton3;

}

public static void main(String args[]){

mbsy=new mianbansy();

}

} // @jve:decl-index=0:visual-constraint="10,10"

大哥~~我还回答了你另一个“编程题”的问题(),运行过了,没问题的,你记得处理那个问题啊~~^_^呵呵……

这个Java程序设计题怎么做

DecimalFormat df = new DecimalFormat();

df.applyPattern("0.00");

double p = 160;

double w = 1000;

double d = 0;

Scanner sc = new Scanner(System.in);

System.out.print("请输入任意s值:");

double s = sc.nextDouble();

if (s 0 s 250) {

d = 0;

} else if (s = 250 s 500) {

d = 0.02;

//System.out.println(s);

} else if (s = 500 s 1000) {

d = 0.05;

} else if (s = 1000 s 2000) {

d = 0.08;

} else if (s = 2000 s 3000) {

d = 0.1;

} else if (s = 3000) {

d = 0.15;

}

double exp = p * w * s * (1 - d);

System.out.println(df.format(exp));

java程序设计题

import java.io.BufferedInputStream;

import java.io.BufferedOutputStream;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

public class Test {

public static void main(String[] args) {

BufferedOutputStream out = null;

try {

out = new BufferedOutputStream(new FileOutputStream(new File("d:/info.txt")));

String line = "第一行文本\n第二行文本";

out.write(line.getBytes());

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

} finally {

if (out != null) {

try {

out.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

BufferedInputStream in = null;

try {

in = new BufferedInputStream(new FileInputStream("d:/info.txt"));

StringBuffer buffer = new StringBuffer();

byte[] buff = new byte[in.available()];

while (in.read(buff) != -1) {

buffer.append(new String(buff));

}

System.out.println(buffer);

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

} finally {

if (in != null) {

try {

in.close();

in = null;

} catch (IOException e) {

e.printStackTrace();

}

}

}

}

}

JAVA程序设计试卷

1.BCD

2.B

3.AB

4.ABCD

5.BC

6.C

7.ABD

8.ACD

9.C

10.A

JAVA程序设计题(很简单的)

你的题有很多错误,我给你改了一下。

1.设变量i和j的定义如下,试分别计算下列表达式的值:

int i=1; double d=1.0;

1题 35/4 [8]

2题 46%9+4*4-2 [15]

3题 45+43%5*(23*3%2)[48]

4题 45+45*50%i-- [45]

5题 45+45*50%(i--) [45]

6题 1.5*3+(++d) [6.5]

7题 1.5*3+d++ [5.5]

8题 i+=3/i+3 [7]

程序阅读题

1给定如下代码,写出程序运行结果

class Example{

public static void main(String arges[]){

int i=0;

do{

System.out.println("doing it for i is:"+i);

}while(--i0);

System.out.println("finish");

}

}

结果如下:

doing it for i is:0

finish

2 阅读程序段写出执行结果

for(int k=1;k=5;k++){

if(k4)break;

System.out.println("k="+k);

}

结果:

k=1

k=2

k=3

k=4

3试写出下列程序段循环的运行结果

int i=1;

while(i10)

if(i++%2==0)

System.out.println(i);

结果:

3

5

7

9

操作题

求1!+2!+...+10!

public static void main(String arges[]){

long sum = 0;

for(int i = 1; i = 10; i++) {

long s = 1;

for(int j = 1; j = i; j++) {

s *= j;

}

sum += s;

}

System.out.println("sum = " + sum);

}

求100之内的所有“完数”。完数是指等于它的因子和的数。例如:6=1+2+3,6=1*2*3,则6是一个完数

public class wanshu{

public static void main(String[] args) {

for(int i = 1; i = 100; i++) {

if(fun(i)) {

System.out.println(i);

}

}

}

public static boolean fun(int num) {

int sum = 0;

for(int i = 1; i num; i++) {

if(num % i == 0) {

sum += i;

}

}

return num == sum;

}

}