Part B:Program decrypts a four-digit numbe import java.awt. public class Decrypt //method main begins execution of Java application public static void main(String args]) int numbe int digitl; 供oNnn int digit4- //enter four digit number to be decrypted de her s the decrypted digits Write code here to display the decrypted number ina message dialog System.exit0)方 }l∥end method mair //end class decrypt 4.下面的程序用来根据输入的产品号和数量计算销售额,请根据/*/中的注释将下面的程序 补充完整,使之编译通过并能正确运行。 import java.awt. import java.te umberFormat; import javax.swing.*; public class Sales vod main(Sing时 double product1=0.product2=0.product3=0.product4=0.product5=0. utstring /Ask the user to enter product number*/ Create while statement that loops until sentinel is entered
=================================== Part B: Program decrypts a four-digit number. =================================== import java.awt.*; import javax.swing.JOptionPane; public class Decrypt { // method main begins execution of Java application public static void main( String args[] ) { int number; // encrypted number int digit1; // first digit int digit2; // second digit int digit3; // third digit int digit4; // fourth digit int decryptedNumber; // decrypted number // enter four digit number to be decrypted number = Integer.parseInt( JOptionPane.showInputDialog( "Enter a four digit number: " ) ); // decrypt /* Write code here that obtains the individual digits of the four-digit number and decrypt them */ /* Write code here that assembles the decrypted digits into the decrypted number */ /* Write code here to display the decrypted number in a message dialog */ System.exit( 0 ); } // end method main } // end class decrypt 4.下面的程序用来根据输入的产品号和数量计算销售额,请根据/**/中的注释将下面的程序 补充完整,使之编译通过并能正确运行。 import java.awt.*; import java.text.NumberFormat; import java.util.Locale; import javax.swing.*; public class Sales { public static void main( String args[] ) { double product1 = 0, product2 = 0, product3 = 0, product4 = 0, product5 = 0; String inputString; int productId = 1; /* Ask the user to enter product number */ /* Create while statement that loops until sentinel is entered */ {
Determine whether user product number is in 1-5*/{ Ifso,ask user to input the quantity sold* else Display error message for invalid product number Ask the user to enter product number }∥end while NumberFormat moneyFormat NumberFormat getCurrencyInstance(Locale.US ) /∥create a summary mess String output "P money.format(product1) the JTextArea outputArea=new JTextArea(6,20); outputarea.set lext(output ) ∥show results System.exit(0 ) }∥end class Sales 第3章类、类的继承和接口 一.概念复习和巩因(请在课后和上机前完成下面的练习) 1.面向对象程序设计的基本特征是(ABCD). A)抽象 B)封装 C)继承 D)多态 2.下面关于类的说法正确的是(ABCD): A)类是Java语言中的- 种复合数据类型。B)类中包含数据变量和方法。 C)类是对所有具有一定共性的对象的抽象。D)Java语言的类只支持单继承 3下列选项4 B)i 用于在定义类 名的关键字是(D。 4定义类头时可以使用的访问 空制符是{C A)private B)protect )publ D)缺省的,即没有访问控制修饰符 5有 个类A,对于其构造函数的声 正确的是(B)。 A)void A(int x) B)A(int x)
/* Determine whether user 抯 product number is in 1-5 */ { /* If so, ask user to input the quantity sold */ /* Write a switch structure here that will compute the total for that product */ } else { /* Display error message for invalid product number */ } /* Ask the user to enter product number */ } // end while // create decimal format to format floating point numbers // with two digits to the right of the decimal point NumberFormat moneyFormat = NumberFormat.getCurrencyInstance( Locale.US ); // create a summary message String output = "Product 1: " + money.format( product1 ); /* write code here for the rest of the summary message it should contain the totals for the rest of the products, each on it 抯 own line */ JTextArea outputArea = new JTextArea( 6, 20 ); outputarea.setText( output ); // show results JOptionPane.showMessageDialog( null, outputArea, "Totals", JOptionPane.INFORMATION_MESSAGE ); System.exit( 0 ); } } // end class Sales 第 3 章 类、类的继承和接口 一. 概念复习和巩固(请在课后和上机前完成下面的练习) 1.面向对象程序设计的基本特征是(ABCD)。 A)抽象 B)封装 C)继承 D)多态 2.下面关于类的说法正确的是(ABCD)。 A)类是 Java 语言中的一种复合数据类型。B) 类中包含数据变量和方法。 C)类是对所有具有一定共性的对象的抽象。D) Java 语言的类只支持单继承。 3.下列选项中,用于在定义类头时声明父类名的关键字是(D)。 A)package B)interface C)class D)extends 4.定义类头时可以使用的访问控制符是(CD)。 A) private B) protected C) public D) 缺省的,即没有访问控制修饰符 5.有一个类 A,对于其构造函数的声明正确的是( B )。 A)void A(int x){...} B)A(int x){...}