第八章第十二题(金融应用:计算税款)(Financial applications: calculating taxes)

第八章第十二题(金融应用:计算税款)(Financial applications: calculating taxes)

  • **8.12(金融应用:计算税款)在这里插入图片描述
    在这里插入图片描述
    **8.12(Financial applications: calculating taxes)
    在这里插入图片描述
    在这里插入图片描述

  • 参考代码:

    package chapter08;
    
    import java.util.Scanner;
    
    public class Code_12 {
        public static void main( String[] args ){
            double sx , sy , ex , ey ;
            line l1 = new line() ;
            line l2 = new line() ;
            Scanner in = new Scanner(System.in) ;
            System.out.print("Enter the endpoints of the first line segment:" ) ;
            sx = in.nextDouble() ;
            sy = in.nextDouble() ;
            ex = in.nextDouble() ;
            ey = in.nextDouble() ;
            l1.set(sx,sy,ex,ey);
            System.out.print("Enter the endpoints of the second line segment:" ) ;
            sx = in.nextDouble() ;
            sy = in.nextDouble() ;
            ex = in.nextDouble() ;
            ey = in.nextDouble() ;
            l2.set(sx,sy,ex,ey) ;
            l1.show_crosser_with(l2) ;
        }
    }
    
    class line{
        private double sx ;
        private double sy ;
        private double ex ;
        private double ey ;
        line(){
            this.sx = 0 ;
            this.sy = 0 ;
            this.ex = 0 ;
            this.ey = 0 ;
        }
        void set( double sx , double sy , double ex , double ey ){
            this.sx = sx ;
            this.sy = sy ;
            this.ex = ex ;
            this.ey = ey ;
        }
        void show_crosser_with( line line2 ){
            double k1 = (ey-sy)/(ex-sx) ;
            double k2 = (line2.ey-line2.sy)/(line2.ex-line2.sx) ;
            if( k1 == k2 ){
                System.out.println( "These two lines are parallel to each other !" ) ;
            }
            else{
                double csx , csy ;
                double b1 = sy - k1*sx ;
                double b2 = line2.sy - k2*line2.sx ;
                csx = (b2-b1)/(k1-k2) ;
                csy = k1*(b2-b1)/(k1-k2) + b1 ;
                System.out.println( "The intersecting point is: (" + csx + ", " + csy + ")" ) ;
            }
        }
    }
    
    
  • 结果显示:

    Enter the endpoints of the first line segment:2 1 4 5
    Enter the endpoints of the second line segment:3 8 7 6
    The intersecting point is: (5.0, 7.0)
    
    Process finished with exit code 0
    
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值