Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Chapter 5 
Lab 3 
Exercise 7 – Page 293 
 
Instructions: 
 
Use the following code for the TestDigitalCamera class: 
 
import java.util.*; 
 
public class TestDigitalCamera  
{ 
 public static void main(String[] args)  
 { 
  DigitalCamera digitalCamera1, digitalCamera2,  
   digitalCamera3, digitalCamera4; 
  String brand; 
  int megapixels; 
  Scanner keyboard = new Scanner(System.in); 
   
  System.out.println("Enter the data for camera 1"); 
  System.out.print("Brand: "); 
  brand = keyboard.nextLine(); 
  System.out.print("Megapixels: "); 
  megapixels = keyboard.nextInt(); 
  keyboard.nextLine(); 
  digitalCamera1 = new DigitalCamera(brand, megapixels); 
   
  System.out.println("\nEnter the data for camera 2"); 
  System.out.print("Brand: "); 
  brand = keyboard.nextLine(); 
  System.out.print("Megapixels: "); 
  megapixels = keyboard.nextInt(); 
  keyboard.nextLine(); 
  digitalCamera2 = new DigitalCamera(brand, megapixels); 
 
  System.out.println("\nEnter the data for camera 3"); 
  System.out.print("Brand: "); 
  brand = keyboard.nextLine(); 
  System.out.print("Megapixels: "); 
  megapixels = keyboard.nextInt(); 
  keyboard.nextLine(); 
  digitalCamera3 = new DigitalCamera(brand, megapixels); 
   
  System.out.println("\nEnter the data for camera 4"); 
  System.out.print("Brand: "); 
  brand = keyboard.nextLine(); 
  System.out.print("Megapixels: "); 
  megapixels = keyboard.nextInt(); 
  keyboard.nextLine(); 
  digitalCamera4 = new DigitalCamera(brand, megapixels); 
 
  System.out.println(); 
  digitalCamera1.display(); 
  digitalCamera2.display(); 
  digitalCamera3.display(); 
  digitalCamera4.display(); 
 
  keyboard.close(); 
 } 
} 
 
Example Output: 
 
Grading: 
 
2 – General, compiles, comments, proper indentation, etc 
2 – Instance variables 
4 – Megapixel logic 
4 – Price logic 
2 – Display method