Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Program {
- public static void main(String[] args) throws Exception {
- Scanner sc = new Scanner (System.in);
- SmartphoneBattery Battery = new SmartphoneBattery();
- System.out.print("What is the type of battery: ");
- Battery.type = sc.nextLine();
- System.out.print("What is the capacity of the battery (mAh): ");
- Battery.capacity = Double.parseDouble(sc.nextLine());
- System.out.print("Adding quantity: ");
- Battery.quantity = Double.parseDouble(sc.nextLine());
- System.out.println();
- Battery.printInfo();
- }
- }
- public class SmartphoneBattery {
- String type;
- double capacity;
- double quantity;
- void printInfo() { System.out.println("Battery type: " + this.type);
- System.out.printf("Battery capacity: %.0f\n" ,this.capacity);
- System.out.printf("Adding quantity: %.0f", this.quantity); }
- void charge(double mAh) throws Exception {
- if ((mAh + this.quantity) > this.capacity) {
- throw new Exception();
- } else {
- this.quantity += mAh;
- }
- }
- public SmartphoneBattery() {
- this.type = "li-ion";
- this.capacity = 3500;
- this.quantity = 3000;
- }
- public SmartphoneBattery(String type, double capacity, double quantity) {
- this.type = type;
- this.capacity = capacity;
- this.quantity = quantity;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement