Ian Chen 發問時間: 電腦與網際網路程式設計 · 8 年前

i have a java problem hurry!

Instructions for your program:· Values for the initial height, the initialvelocity, and angle of inclination for the missile should be input entered bythe user. Include helpful prompts forthe user, specifying the correct units required. · Your program should compute and display as outputthe maximum horizontal distance the missile travels, as well as the maximumheight of its trajectory.· The calculations should be done using doubleprecision floating point arithmetic. · Develop your program incrementally, testingfrequently to catch errors early.· Include detailed comments in your programexplaining each step. · Select meaningful names for the many variablesused in formulas required for this program.· Define the acceleration due to gravity (9.8, in m/s2)as a constant. Use Math.PI as the value for p.· To perform the calculations that are part ofthis problem, it will be necessary for statements you write in the main methodin your program to include the use of other Java methods predefined in the Mathclass, such as trigonometric methods and exponent methods. A partial listingand explanation of some of these methods may be found in Chapter 5 of yourtextbook, Section 5.10. You also should startusing the Java Application Programming Interface (API) documentation, locatedat http://oracle.com/javase/7/docs/api,which provides complete Java documentation. 小第我因為字數的關係,沒辦法po全文,所以請到我的部落格看全內容~please step by step http://tw.myblog.yahoo.com/jw!63M7ccGbERnfzClkrkUE...

1 個解答

評分
  • 8 年前
    最佳解答

    請參考我的做法

    import javax.swing.JOptionPane;

    public class Y3459 {

    final static double g = 9.8D;

    static double agl, vo, vxo = 0D, vyo = 0D, x, xo = 0D, y, yo, t, tf;

    public static void main(String[] args) {

    // input agl, vo, and y0

    yo = Double.parseDouble(JOptionPane.showInputDialog(null,

    "Enter initial height(m):"));

    vo = Double.parseDouble(JOptionPane.showInputDialog(null,

    "Enter initial velocity(m/sec):"));

    agl = Double.parseDouble(JOptionPane.showInputDialog(null,

    "Enter angle of inclination(deg):"));

    agl = Math.toRadians(agl);

    vxo = vo * Math.cos(agl);

    vyo = vo * Math.sin(agl);

    tf = (vyo + Math.sqrt(vyo * vyo + 2 * g * yo)) / g;

    // decimal number with max 4 digits after decimal separator

    String format = "%.4f";

    t = vyo / g;

    JOptionPane.showMessageDialog(null,

    "The time missile hits the ground is at " +

    String.format(format, tf) + " second\n" +

    "The max horizontal distance missile travels is " +

    String.format(format, getX(tf)) + " meters\n" +

    "The max vertical height of the trajectory is " +

    String.format(format, getY(t)) + " meters");

    }

    static double getX(double t) {

    return vxo * t;

    }

    static double getY(double t) {

    return yo + vyo * t - g * t * t / 2;

    }

    }

還有問題?馬上發問,尋求解答。