Create a class for Shutterbug\'s Camera Store, which is having a digital camera
ID: 641540 • 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 then 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 the values for the camera brand and number of megapixels, and display the values.
This is in Java.
Needs to be 2 programs
Explanation / Answer
import java.util.Scanner;
public class Camera{
String brand;
int megapixels;
public void Camera(String brand, int megapixels){
this.brand = brand;
this.megapixels = megapixels;
}
public void details(){
System.out.println("your camera brand is");
System.out.println(brand);
if(megapixels<=6){
cost = 99;
}
else{
cost = 129;
}
System.out.println(" cost of your camera is");
System.out.println(cost);
}
public void static main(args[]){
Scanner sc = new Scanner(System.in);
System.out.println("Enter brand of your camera");
String camera_brand = sc.nextLine();
System.out.println("enter pixels");
int pixels = sc.nextInt();
Camera cam = new Camera(camera,pixels);
cam.details();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.