Knowee
Questions
Features
Study Tools

Analyze the below program, and fill the correct code so that it produces the below output: 0 101class Book { private int bookId; private double bookPrice; public int getBookId() { return bookId; } public void setBookId(int bookId) { this.bookId = bookId; } public double getBookPrice() { return bookPrice; } public void setBookPrice(double bookPrice) { this.bookPrice = bookPrice; }}public class Test { public static void main(String a[]) { Book bobj=new Book();  blank  blank  blank }}Note : Same drag option can be used multiple times. Analyse and use the correct optionSystem.out.println(bobj.getBookPrice()); bobj.setBookId(101); System.out.println(bobj.getBookId());

Question

Analyze the below program, and fill the correct code so that it produces the below output: 0 101class Book { private int bookId; private double bookPrice; public int getBookId() { return bookId; } public void setBookId(int bookId) { this.bookId = bookId; } public double getBookPrice() { return bookPrice; } public void setBookPrice(double bookPrice) { this.bookPrice = bookPrice; }}public class Test { public static void main(String a[]) { Book bobj=new Book();  blank  blank  blank }}Note : Same drag option can be used multiple times. Analyse and use the correct optionSystem.out.println(bobj.getBookPrice()); bobj.setBookId(101); System.out.println(bobj.getBookId());

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct code to fill in the blanks would be:

bobj.setBookId(101);
System.out.println(bobj.getBookId());
bobj.setBookPrice(0);
System.out.println(bobj.getBookPrice());

So the complete code would be:

class Book {   
    private int bookId;   
    private double bookPrice;   
    public int getBookId() {          
        return bookId;    
    }     
    public void setBookId(int bookId) {            
        this.bookId = bookId;     
    }     
    public double getBookPrice() {         
        return bookPrice;
    }    
    public void setBookPrice(double bookPrice) {           
        this.bookPrice = bookPrice;     
    }
}

public class Test  {   
    public static void main(String a[]) {
        Book bobj=new Book();          
        bobj.setBookId(101);
        System.out.println(bobj.getBookId());
        bobj.setBookPrice(0);
        System.out.println(bobj.getBookPrice());
    }
}

This code first sets the bookId to 101 and then prints it. After that, it sets the bookPrice to 0 and then prints it. The output will be:

101
0.0

This problem has been solved

Similar Questions

Select the correct answerWhat will be the output of the following Java program? class access { public int x; static int y; void cal(int a, int b) { x += a ; y += b; } } class static_specifier { public static void main(String args[]) { access obj1 = new access(); access obj2 = new access(); obj1.x = 0; obj1.y = 0; obj1.cal(1, 2); obj2.x = 0; obj2.cal(2, 3); System.out.println(obj1.x + " " + obj2.y); } }Options3 22 31 21 5

Given1. class Program{2. 3.     public static void main(String[] args){4. 5.         int val1 = 1;6.         int val2 = 2;7. 8.         if(val1 == val2)9.              System.out.print("1");10.         if(val1!= val2)11.              System.out.print("2");12.         if(val1 > val2)13.              System.out.print("3");14.         if(val1 < val2)15.             System.out.print(4);16.         if(val1 => val2)17.             System.out.print("5");18. 19.     }20. }     Which is the output?*24524Compilation fails due to an error on line 16Compilation fails due to multiple errorsNone of above.

Analyze the following code:public class Test {   public static void main(String[] args) {     int[] x = {1, 2, 3, 4};     int[] y = x;    x = new int[2];    for (int i = 0; i < y.length; i++)      System.out.print(y[i] + " ");  }}Group of answer choicesThe program displays 0 0 3 4The program displays 0 0The program displays 0 0 0 0The program displays 1 2

Select the correct answerPredict the output of the following program.? class CT{    int i = 1;    int j = 2;    CT func(CT obj)    {        CT obj3 = new CT();        obj3 = obj;        obj3.i = obj.i++ + ++obj.j;        obj.j = obj.j;        return obj3;    }    public static void main(String[] args)    {        CT obj1 = new CT();        CT obj2 = obj1.func(obj1);        System.out.println("obj1.i = " + obj1.i + "  obj1.j = " + obj1.j);        System.out.println("obj2.i = " + obj2.i + "  obj1.j = " + obj2.j);    }}OptionsCompilation errorobj1.i = 4 obj1.j = 3obj2.i = 4 obj2.j = 3obj1.i = 1 obj1.j = 2obj2.i = 4 obj2.j = 3non of these

Given1. public class Certification{2. private String name;3. private double price;4. 5. public Certification(String s,double d){6. name = s;7. price = d;8. }9. 10. public double getPrice(){11. return price;12. }13. 14. public String getName(){15. return name;16. }17. }18. 19. //Assume necessary imports have done20. 21. public class CertifyTest {22. 23. public static void main(String[] args) {24. 25. List<Certification> certs = new ArrayList<Certification>();26. 27. certs.add(new Certification("1Z0-803",120));28. certs.add(new Certification("1Z0-804",250));29. certs.add(new Certification("1Z0-805",175));30. certs.add(new Certification("1Z0-808",150));31. certs.add(new Certification("1Z0-810",225));32. 33. //insert here34. 35. for(Certification c : certs){36. if(filter.test(c)){37. System.out.println(c.getName());38. }39. }40. }41. 42. }Suppose we have to print only the certifications where price are higher than 180, which of the following insert at line 33 will achieve that?*Predicate<Certification> filter = (c) -> return c.getPrice() > 180;Predicate <Certification> filter = (c) -> {return c.getPrice() > 180;};Consumer <Certification> filter = () -> {return c.getPrice() > 180;};Consumer <Certification> filter = (c) -> {return c.getPrice() > 180;};Supplier <Certification> filter = (c) -> {return c.getPrice() > 180;};

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.