资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

用java代码写冰墩墩 用java代码写冰墩墩作业

如何用java写这段代码?

import java.security.InvalidKeyException;import java.security.NoSuchAlgorithmException;import javax.crypto.BadPaddingException;import javax.crypto.Cipher;import javax.crypto.IllegalBlockSizeException;import javax.crypto.KeyGenerator;import javax.crypto.NoSuchPaddingException;import javax.crypto.SecretKey;public class JEncrytion{

创新互联建站是一家专业提供潞州企业网站建设,专注与网站设计制作、成都网站制作、成都h5网站建设、小程序制作等业务。10年已为潞州众多企业、政府机构等服务。创新互联专业网站建设公司优惠进行中。

public static void main(String[] argv) {

try{ KeyGenerator keygenerator = KeyGenerator.getInstance("DES"); SecretKey myDesKey = keygenerator.generateKey();

Cipher desCipher; // Create the cipher

desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding");

// Initialize the cipher for encryption

desCipher.init(Cipher.ENCRYPT_MODE, myDesKey); //sensitive information

byte[] text = "No body can see me".getBytes();

System.out.println("Text [Byte Format] : " + text);

System.out.println("Text : " + new String(text));

// Encrypt the text

byte[] textEncrypted = desCipher.doFinal(text);

System.out.println("Text Encryted : " + textEncrypted);

// Initialize the same cipher for decryption

desCipher.init(Cipher.DECRYPT_MODE, myDesKey); // Decrypt the text

byte[] textDecrypted = desCipher.doFinal(textEncrypted);

System.out.println("Text Decryted : " + new String(textDecrypted));

}catch(NoSuchAlgorithmException e){

e.printStackTrace();

}catch(NoSuchPaddingException e){

e.printStackTrace();

}catch(InvalidKeyException e){

e.printStackTrace();

}catch(IllegalBlockSizeException e){

e.printStackTrace();

}catch(BadPaddingException e){

e.printStackTrace();

}

}

}

用JAVA编写一个程序,要求如下:

实现代码如下:

Student类:

public class Student {

private String name;

private String sex;

private int age;

private double chinese;

private double math;

private double english;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getSex() {

return sex;

}

public void setSex(String sex) {

this.sex = sex;

}

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

public double getChinese() {

return chinese;

}

public void setChinese(double chinese) {

this.chinese = chinese;

}

public double getMath() {

return math;

}

public void setMath(double math) {

this.math = math;

}

public double getEnglish() {

return english;

}

public void setEnglish(double english) {

this.english = english;

}

}

-----------------------------------------------------------------

StudentTest类:(测试类)

import java.util.Scanner;

public class StudentTest {

public static void main(String[] args) {

Student student = new Student();

Scanner sc = new Scanner(System.in);

System.out.println("请输入姓名:");

student.setName(sc.next());

System.out.println("请输入性别:");

student.setSex(sc.next());

System.out.println("请输入年龄:");

student.setAge(sc.nextInt());

System.out.println("请输入语文成绩、数学成绩、英语成绩:");

student.setChinese(sc.nextDouble());

student.setMath(sc.nextDouble());

student.setEnglish(sc.nextDouble());

Double count = student.getChinese()+ student.getMath()+student.getEnglish();

System.out.println("姓名:"+student.getName()+" 性别:"+student.getSex()+" 年龄:"+student.getAge());

System.out.println("总分:"+count+" 平均分:"+count/3);

}

}

运行结果为:

使用java编写代码如下要求

NewPhone类

package com.baidu.question;

public class NewPhone extends Phone {

private boolean mute = true;

@Override

public void call() {

if(mute){

super.call();

}else{

System.out.println("语音已关闭");

}

}

//这里是直接设置

public void setMute(boolean mute){

this.mute=mute;

}

//担心你的题目是要求两种方法,写的第二种,下面两个方法负责开关

public void openMute(){

this.mute=true;

/*

* 也可以这样写

* setMute(true);

* 下边的方法一样

* */

}

public void closeMute(){

this.mute = false;

}

}

Phone类

package com.baidu.question;

public class Phone {

public void call(){

System.out.println("打电话");

}

}

测试类

package com.baidu.question;

public class PhoneTest {

public static void main(String[] args) {

Phone phone = new Phone();

phone.call();

NewPhone newPhone = new NewPhone();

newPhone.call();

newPhone.setMute(false);

newPhone.call();

newPhone.openMute();

newPhone.call();

newPhone.closeMute();

newPhone.call();

}

}

测试结果

打电话

打电话

语音已关闭

打电话

语音已关闭

求大神用Java编写出这个程序,要有具体代码,万分感激,定采纳

按照你的要求编写的JavaGUI程序如下:

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JTextField;

public class HH extends JFrame implements ActionListener{

JPanel jp1=new JPanel();

JPanel jp2=new JPanel();

JPanel jp3=new JPanel();

JTextField jtf=new JTextField(20);

JButton jb1=new JButton("显示");

JButton jb2=new JButton("清除");

HH(){

jb1.addActionListener(this);

jb2.addActionListener(this);

jp1.setLayout(new GridLayout(2,1));

jp3.add(jtf);

jp2.add(jb1);jp2.add(jb2);

jp1.add(jp3);jp1.add(jp2);

getContentPane().add(jp1);

setSize(300, 120);

setLocationRelativeTo(null);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setVisible(true);

}

@Override

public void actionPerformed(ActionEvent e) {

if(e.getSource()==jb1){

jtf.setText("java程序设计");

}

if(e.getSource()==jb2){

jtf.setText("");

}

}

public static void main(String[] args) {

new HH();

}

}


分享题目:用java代码写冰墩墩 用java代码写冰墩墩作业
文章网址:http://cdkjz.cn/article/dohcheh.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220