Java语言程序设计基础篇 第八章 课后编程答案

本文提供了Java语言程序设计基础篇第八章的课后编程题答案,帮助学习者巩固Java基础知识。
摘要由CSDN通过智能技术生成

 

原博链接:Java语言程序设计基础篇 第八章 课后编程答案

 

import java.util.Scanner;

public class ch0801{
	public static void main( String[] args ){
		Rectangle r1 = new Rectangle(4,40) ;
		Rectangle r2 = new Rectangle(3.5,35.9) ;
		System.out.println("Rectangle1 : width = " + r1.width + " , height = " + r1.height + " , area = " + r1.getArea() + " , perimeter = " + r1.getPerimeter() ) ;
		System.out.println("Rectangle2 : width = " + r2.width + " , height = " + r2.height + " , area = " + r2.getArea() + " , perimeter = " + r2.getPerimeter() ) ;

	}
}

class Rectangle{
	double width ;
	double height ;
	Rectangle(){
		width = height = 1 ;
	}
	Rectangle( double w , double h ){
		width = w ;
		height = h ;
	}
	double getArea(){
		return width*height ;
	}
	double getPerimeter(){
		return (width+height)*2 ;
	}
}
import java.util.Scanner;

public class ch0802{
	public static void main( String[] args ){
		Stock myStock = new Stock("JAVA","Sum Microsystems Inc") ;
		myStock.setPreviousClosingPrice(4.5) ;
		myStock.setCurrentPrice(4.35) ;
		System.out.println("Has changed " + myStock.getChangePerent() ) ;
	}
}

class Stock{
	private String symbol ;
	private String name ;
	private double previousClosingPrice ;
	private double currentPrice ;
	Stock(){

	}
	Stock( String symbol , String name ){
		this.symbol = symbol ;
		this.name = name ;
	}
	double getChangePerent(){
		return (currentPrice-previousClosingPrice)/previousClosingPrice ;
	}
	void setPreviousClosingPrice( double previousClosingPrice ){
		this.previousClosingPrice = previousClosingPrice ;
	}
	void setCurrentPrice( double currentPrice ){
		this.currentPrice = currentPrice ;
	}
}

 

import java.util.Date;
public class ch0803{
	public static void main( String[] args ){
		Date date = new Date() ;
		long goesTime = 10000 ;
		int times = 1 ;
		while( times <= 8 ){
			date.setTime(goesTime);
			System.out.println(date.toString()) ;
			goesTime = goesTime * 10 ;
			times++ ;
		}
	}
}

 

import java.util.Random;

public class ch0804{
	public static void main( String[] args ){
		Random random = new Random(1000) ;
		int i = 0 ;
		while( i < 50 ){
			int x = random.nextInt(100) ;
			System.out.println(x) ;
			++i ;
		}
	}
}

 

import java.util.GregorianCalendar;

public class ch0805{
	public static void main( String[] args ){
		myGregorianCalendar calendar = new myGregorianCalendar() ;
		calendar.show_date() ;
		calendar.set(123456789765L) ;
		calendar.show_date() ;
	}
}

class myGregorianCalendar{
	private GregorianCalendar ca ;
	private int year ;
	private int month ;
	private int day ;
	myGregorianCalendar(){
		ca = new GregorianCalendar() ;
		year = ca.get(GregorianCalendar.YEAR) ;
		month = ca.get(GregorianCalendar.MONTH) + 1 ;
		day = ca.get(GregorianCalendar.DAY_OF_MONTH) ;
	}
	void sho
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值