Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3. Suppose that a class named Bicycle contains a private nonstatic integer named

ID: 3844052 • Letter: 3

Question

3. Suppose that a class named Bicycle contains a private nonstatic integer named height, a public nonstatic String named model, and a public static integer named wheels. Which of the following are legal statements in a class named BicycleDemo that has instantiated an object as Bicycle myBike new Bicycle C);? f. Bicycle. model Hurricane a. myBike height 26; b. my Bike model Cyclone g. Bicycle. int 3 3; c. myBike Wheels 3 d. my Bike .model 108; i. Bicycle wheels 2 e. Bicycle height 24; j. Bicycle yourBike myBike

Explanation / Answer

3)

Ans)

b) myBike.model="Cyclone";
c) myBike.wheels=3;

i) Bicycle.wheels=2;
j) Bicycle yourBike=myBike;

Reason:

b) myBike.model="Cyclone";

As model variable is public we can access it from out side the class and we can do initialization.
c) myBike.wheels=3;

wheels is public static variable we can access it from out side the class and by using the object reference and we can initialize it with values.

i) Bicycle.wheels=2;

As wheels is public static variable we can access it by using the class reference and also by using Class name.
j) Bicycle yourBike=myBike;

here we are assigning the reference "myBike" which is of Bicycle class to another Bicycle class reference "yourBike".Which is valid.

_________________________

6)

BookStoreCredit.java

public class BookStoreCredit {

   //Declaring varibles
   private double grade;
   private String name;
  
   //Zero argumented Constructor
   public BookStoreCredit() {
       super();
   }
  
   //Setters and getters
   public double getGrade() {
       return grade;
   }


   public void setGrade(double grade) {
       this.grade = grade;
   }

   public String getName() {
       return name;
   }


   public void setName(String name) {
       this.name = name;
   }


   //Method which calculate the credit amount based on grade Point average
   void calGrade(double grade)
   {
       System.out.println("For the grade point average of "+grade+" "+name+" receives an amount of $"+grade*10);
   }

}

_________________________

Test.java

import java.util.Scanner;

public class Test {

   public static void main(String[] args) {
  
   //Declaring variables
   String name;
   double gradePointAvg;
  
   //Scanner object is used to get the inputs entered by the user
   Scanner sc=new Scanner(System.in);

   //Getting the inputs entered by the user
   System.out.print("Enter the student name :");
   name=sc.next();
  
   System.out.print("Enter the grade point average :");
   gradePointAvg=sc.nextDouble();
  
   //Creating an class object
   BookStoreCredit bsc=new BookStoreCredit();
  
   //Setting the name
   bsc.setName(name);
  
   /* Calculating the credit amount by passing the grade
   * point average as input to the method
   */
   bsc.calGrade(gradePointAvg);

   }

}

______________________

Output:

Enter the student name :Williams
Enter the grade point average :4.4
For the grade point average of 4.4 Williams receives an amount of $44.0


_____________Could you rate me well.Plz .Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote