Create a class for Shutterbug’s Camera Store, which is having a digital camera s
ID: 3684811 • Letter: C
Question
Create a class for Shutterbug’s Camera Store, which is having a digital camera sale. The class is named DigitalCamera, and it contains data fields for a brand, the number of megapixels in the resolution, and price. Include a constructor that takes arguments for the brand and megapixels. If the megapixel parameter is greater than 10, the constructor sets it to 10. The sale price is set based on the resolution; any camera with 6 megapixels or fewer is $99, and all other cameras are $129. Also include a method that displays DigitalCamera details. Write an application named TestDigitalCamera in which you instantiate at least four objects, prompt the user for values for the camera brand and number of megapixels, and display all the values. Save the files as DigitalCamera.java and TestDigitalCamera.java.
Explanation / Answer
public class DigitalCamera {
private String camBrnd ;
private int camMPixels ;
private double cost ;
public DigitalCamera ( String brand ,int mPixls ) {
camBrnd = brand ;
if( mPixls >10 ) {
camMPixels =10 ;
}
else {
camMPixels = mPixls ;
}
if( mPixls <=6 ) {
cost = 99.00 ;
}
else {
cost = 129.00 ;
}
}
public void displayCameraDetails ( ) {
System.out.println ( " Brand Name : " +camBrnd ) ;
System.out.println ( " Megapixels : " +camMPixels ) ;
System.out.println ( " cost : " +cost ) ;
}
}
public class TestDigitalCamera {
public static void main ( String[] args ) {
DigitalCamera cam01 =new DigitalCamera ( " FujiFilm " ,10 ) ;
DigitalCamera cam02 =new DigitalCamera ( " JVC " ,4 ) ;
DigitalCamera cam03 =new DigitalCamera ( " Nikon " ,6 ) ;
DigitalCamera cam04 =new DigitalCamera ( " Cannon " ,12 ) ;
cam01.displayCameraDetails ( ) ;
cam02.displayCameraDetails ( ) ;
cam03.displayCameraDetails ( ) ;
cam04.displayCameraDetails ( ) ;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.