【格码顶端编程】写一个符合实际情况的航天小学生类Student

class Student:
	schoolName="Space Primary School"
	def __init__(self,name,sex,age=6,lovername="无"):
		self.__name=name
		self.sex=sex
		self.__age=age
		self.__lovername=lovername
		print(self.__name,"已成航小学生.")
	def __del__(self):
		print(self.__name,"不是航小学生")
	def yourName(self):
		print("My Name is",self.__name)
	def yourAge(self):
		if(self.sex=='f'and self.__age>=30):
			print("I am %d years old."%((self.__age)-10))
		else:
			print("I am %d years old."%(self.__age))
	def yourSchoolName(self):
		print("My School Name is",self.schoolName)
		
ob1=Student("马","m",6,"")
ob2=Student("刘","f",30)
ob3=Student("袁","m",4,"冰冰")
ob1.yourName()
ob1.yourAge()
ob2.yourAge()
ob3.yourName()
ob3.yourSchoolName()
del ob2
Student.schoolName="New Hope School"
ob3.yourSchoolName()


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
恩尼格码密码机是一种简单的替换密码,它使用一个密钥表来将明文字符替换为密文字符。Java可以很容易地实现这个密码机的加密和解密过程。以下是一个示例程序: ```java import java.util.HashMap; import java.util.Map; public class EnigmaCipher { private Map<Character, Character> keyTable; public EnigmaCipher(String key) { keyTable = new HashMap<>(); String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; for (int i = 0; i < alphabet.length(); i++) { char c = alphabet.charAt(i); char k = key.charAt(i); keyTable.put(c, k); } } public String encrypt(String plaintext) { StringBuilder ciphertext = new StringBuilder(); for (int i = 0; i < plaintext.length(); i++) { char c = plaintext.charAt(i); if (Character.isUpperCase(c)) { c = keyTable.get(c); } ciphertext.append(c); } return ciphertext.toString(); } public String decrypt(String ciphertext) { StringBuilder plaintext = new StringBuilder(); for (int i = 0; i < ciphertext.length(); i++) { char c = ciphertext.charAt(i); if (Character.isUpperCase(c)) { for (Map.Entry<Character, Character> entry : keyTable.entrySet()) { if (entry.getValue() == c) { c = entry.getKey(); break; } } } plaintext.append(c); } return plaintext.toString(); } public static void main(String[] args) { String key = "QWERTYUIOPASDFGHJKLZXCVBNM"; EnigmaCipher cipher = new EnigmaCipher(key); String plaintext = "HELLO WORLD"; String ciphertext = cipher.encrypt(plaintext); String decryptedText = cipher.decrypt(ciphertext); System.out.println("Plaintext: " + plaintext); System.out.println("Ciphertext: " + ciphertext); System.out.println("Decrypted text: " + decryptedText); } } ``` 在这个示例程序中,我们创建了一个 `EnigmaCipher` 类,它接受一个密钥表作为构造函数的参数。`encrypt()` 方法接受明文字符串并返回密文字符串,`decrypt()` 方法接受密文字符串并返回明文字符串。我们还提供了一个 `main()` 方法来演示如何使用这个类。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

gCodeTop 格码拓普 老师

您的鼓励.我的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值