java题目,要求写代码Book.java
package com.books;
public abstract class Book {
private int page;
private double price;
【java类与应用题目代码 java类例题】 private double zheKou;
public abstract void printPrice();
public Book(int page, double price, double zheKou) {
super();
this.page = page;
this.price = price;
this.zheKou = zheKou;
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public double getZheKou() {
return zheKou;
}
public void setZheKou(double zheKou) {
this.zheKou = zheKou;
}
}
JiaoCai.java
package com.books;
public class JiaoCai extends Book{
public JiaoCai(int page, double price, double zheKou) {
super(page, price, zheKou);
}
@Override
public void printPrice() {
System.out.println(getPage() * 0.05 * getZheKou() * getPrice());
}
}
KeJi.java
package com.books;
public class KeJi extends Book {
public KeJi(int page, double price, double zheKou) {
super(page, price, zheKou);
}
@Override
public void printPrice() {
System.out.println(getPage() * 0.1 * getZheKou() * getPrice());
}
}
WenYi.java
package com.books;
public class WenYi extends Book{
public WenYi(int page, double price, double zheKou) {
super(page, price, zheKou);
}
@Override
public void printPrice() {
System.out.println(getPage() * 0.08 * getZheKou() * getPrice());
}
}
测试类 。Test.java
package com.books;
public class Test {
public static void main(String[] args) {
int page = 530;
double zheKou = 0.7;
double price = 100;
Book book = new KeJi(page, price, zheKou);
book.printPrice();
book = new WenYi(page, price, zheKou);
book.printPrice();
book = new JiaoCai(page, price, zheKou);
book.printPrice();
}
}
有什么不懂的加我QQ,详解
java题目代码?代码如下java类与应用题目代码,Rectangle类在java.lang包下有同名类java类与应用题目代码,如需引包请注意java类与应用题目代码,望采纳 。
补充java类与应用题目代码:
Rectangle类
package com.baidu.question183173554138589044;
public class Rectangle {
private double width;
private double height;
public void setRectangle(int w, int h){
if(w0h0){
width = w;
height = h;
}else{
System.out.println("错误java类与应用题目代码:长宽需要大于0");
}
}
public double getArea() {
return width*height;
}
}
运行主类
package com.baidu.question183173554138589044;
public class Main {
public static void main(String[] args) {
Rectangle rect = new Rectangle();
rect.setRectangle(5,6);
System.out.println(rect.getArea());
}
}
有九道JAVA与面向对象的实践题目不会做?。∏蟾呤职汛敫蚁驴梢月穑啃恍焕?/h2>7.
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ";quot;
html
head
title计算器/title
style type="text/css"
input{
height:1.5em;}
.style1{
font-size:18px}
.height{
height:1.2em;}
/style
script language="javascript"
function computer(op){
var num1,num2,result;
num1 = parseFloat(document.form1.textname1.value);
num2 = parseFloat(document.form1.textname2.value);
if(op==" ")
result = num1num2;
document.form1.textResult.value=https://www.04ip.com/post/result;
if(op=="-")
result = num1 - num2;
document.form1.textResult.value = https://www.04ip.com/post/result;
if(op=="*")
result = num1 * num2;
document.form1.textResult.value = https://www.04ip.com/post/result;
if(op=="/"num2!=0)
result = num1/num2;
document.form1.textResult.value = https://www.04ip.com/post/result;
}
/script
/head
body
form name="form1"
center
table width="500" height="300" border="0" background="images/water001.jpg"
tr
tdwidth="183" height="61"img src="https://www.04ip.com/post/images/baidu_logo.gif"width="182" height="54"//td
td width="219"span class="style1"百度计算器/span/td
/tr
tr
td colspan="2"span class="style1"第一个数java类与应用题目代码:input type="text" name="textname1"//span/td
/tr
tr
td colspan="2"span class="style1"第二个数java类与应用题目代码:input type="text" name="textname2"//span/td
/tr
tr
td colspan="2"
input class="height" type="button" value="" onClick="computer(' ')"/nbsp;nbsp;nbsp;
input class="height" type="button" value="https://www.04ip.com/post/-" onClick="computer('-')"/nbsp;nbsp;nbsp;
input class="height" type="button" value="https://www.04ip.com/post/*" onClick="computer('*')"/nbsp;nbsp;nbsp;
input class="height" type="button" value="https://www.04ip.com/" onClick="computer('/')"/
/td
/tr
tr
td colspan="2"span class="style1"计算结果:input type="text" name="textResult"//span/td
/tr
/table
/center
/form
/body
/html
一道Java编程题目 , 新手求详细代码import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class _1 {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
String zifuchuan = new String("");
int hanzishu = 0;
int zimu = 0;
int kongge = 0;
int shuzi = 0;
int qita = 0;
System.out.print("请输入一行字符:");
BufferedReader stdin = new BufferedReader(new InputStreamReader(
System.in));
zifuchuan = stdin.readLine();
byte[] bytes = zifuchuan.getBytes();
for (int i = 0; ibytes.length; i) {
if ((bytes[i] = 65bytes[i] = 90)
|| (bytes[i] = 97bytes[i] = 122))
zimu;
else if (bytes[i] == 32)
kongge;
else if (bytes[i] = 48bytes[i] = 57)
shuzi;
else if (bytes[i]0)
hanzishu;
else
qita;
}
System.out.println("字符串所占字节个数为:"bytes.length);
System.out.println("汉字个数为:"hanzishu / 2);
System.out.println("英文字母个数为:"zimu);
System.out.println("空格个数为:"kongge);
System.out.println("数字个数为:"shuzi);
System.out.println("其他字符个数为:"qita);
}
}
求助大神如何用Java写出这两个题目的代码?第一题
package baidu;
public class Student {
protected String name;
protected int age;
public Student(String name, int age) {
this.name = name;
this.age = age;
}
public void show(){
System.out.println("name = "name);
System.out.println("age = "age);
}
}
---------------------------------
package baidu;
public class Undergraduate extends Student {
private String degree;
public Undergraduate(String name, int age, String degree) {
super(name, age);
this.degree = degree;
}
public void show(){
System.out.println("name = "name);
System.out.println("age = "age);
System.out.println("degree = "degree);
}
}
------------------------
package baidu;
public class TestRun {
public static void main(String[] args) {
Student s = new Student("singi",12);
s.show();
Undergraduate ug = new Undergraduate("lily",23,"本科");
ug.show();
}
}
输出:
name = singi
age = 12
name = lily
age = 23
degree = 本科
第二题:
package baidu;
public class Man {
String name;
public Man(String name) {
this.name = name;
}
public void business(){
System.out.println("在方法内输出谈生意");
}
}
----------------
package baidu;
public class SuperMan extends Man {
String name;
public SuperMan(String name, String name1) {
super(name);
this.name = name1;
}
@Override
public void business() {
System.out.println("在方法内输出谈几个亿的大单子");
}
public void fly(){
System.out.println("在方法内输出超人不会飞");
}
}
------------------
package baidu;
public class TestMan {
public static void main(String[] args) {
Man m = new Man("singi");
System.out.println(m.name);
m.business();
SuperMan sm = new SuperMan("lily","xiaoming");
System.out.println(sm.name);
sm.business();
sm.fly();
}
}
输出:
singi
在方法内输出谈生意
xiaoming
在方法内输出谈几个亿的大单子
在方法内输出超人不会飞
java练习题求完整代码按照题目要求编写的用javaBean规范设计的学生类Student的Java程序如下
需要创建user.java.test包,把Student.java文件和Test.java文件放入包中,编译Student.java文件并且编译运行Test.java文件得到运行结果
Student.java文件代码如下
package user.java.test;
import java.io.Serializable;
public class Student implements Serializable{
private static final long serialVersionUID = 1L;
private String no;
private String name;
private double score;
public Student(){}
public Student(String no,String name,double score){
this.no=no;
this.name=name;
this.score=score;
}
public String getNo(){ return no;}
public void setNo(String no){ this.no=no;}
public String getName(){ return name;}
public void setName(String name){ this.name=name;}
public double getScore(){ return score;}
public void setScore(double score){ this.score=score;}
public String toString(){
return "学号:" no ",姓名:" name ",成绩:" score;
}
public static double getAvg(Student[] sArray){
double sum=0,avg;
for(int i=0;isArray.length;i){
sum=sum sArray[i].getScore();
}
avg=sum/sArray.length;
return avg;
}
}
Test.java文件代码如下
package user.java.test;
public class Test{
public static void main(String[] args){
Student[] sArray=new Student[5];
sArray[0]=new Student("001","张三",89.5);
sArray[1]=new Student("002","李四",82.5);
sArray[2]=new Student("003","王五",93);
sArray[3]=new Student("004","赵六",73.5);
sArray[4]=new Student("005","孙七",66);
System.out.println("这些学生的平均分:" Student.getAvg(sArray));
for(int i=0;isArray.length;i){
System.out.println(sArray[i].toString());
}
}
}
java类与应用题目代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java类例题、java类与应用题目代码的信息别忘了在本站进行查找喔 。
推荐阅读
- 政府如何规范电商,政府如何规范电商行为
- uhd620显卡怎么样,uhd620属于什么显卡
- 游戏益智解谜小游戏,好玩的益智解谜游戏
- c语言时间函数1000秒 c语言中时间函数
- 微信7.0.0安卓正式版,微信7010 安卓正式版
- 显卡硬盘松动怎么办啊,显卡硬盘松动怎么办啊视频
- sqlserver修改字段不能为空,sqlserver修改字段类型报错
- linux命令输入程序 linux输入输出命令
- java代码舆情分析,舆情软件分析