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

i need the program to be written in simple way so i can understand please In thi

ID: 669199 • Letter: I

Question

i need the program to be written in simple way so i can understand please

In this exercise you will design the class BooksExpenses.
a. Each object of this can hold the name of a person, ID, number of books bought, and amount

spent.
b. Include the methods to perform the various operations on the objects of the class such as set,

and get a person’s name, person’s ID, number of books bought and the amount spent. c. Write two more member methods: BuymoreBooks, SellBooks
d. Also write a program to test your class

Explanation / Answer

import java.io.*;
import java.util.*;

class BooksExpenses{
   String person;
   int id;
   int books;
   double amount;
   public BooksExpenses(String p,int i,int b,double a){
       person = p;
       id = i;
       books = b;
       amount = a;
   }
   void set_person(String p){
       person = p;
   }
   void set_id(int i){
       id = i;
   }
   void set_books(int b){
       books = b;
   }
   void set_amount(double a){
       amount = a;
   }

   String get_person(){
       return person;
   }
   int get_id(){
       return id;
   }
   int get_books(){
       return books;
   }
   int get_amount(){
       return amount;
   }

   void BuymoreBooks(){
       Scanner sc = new Scanner(System.in);
       System.out.print("Do you want to buy more books (enter Y for yes otherwise N) ");
       String s = sc.nextLine();
       if (s.charAt(0) == 'y' || s.charAt(0) == 'Y'){
           System.out.print("How many you want to by : ");
           int n = Integer.parseInt(sc.nextLine());
           books += n;
           amount += 200*n;
       }
   }

   void sellBooks(){
       Scanner sc = new Scanner(System.in);
       System.out.print("Do you want to sell any books (enter Y for yes otherwise N) ");
       String s = sc.nextLine();
       if (s.charAt(0) == 'y' || s.charAt(0) == 'Y'){
           System.out.print("How many you want to sell : ");
           int n = Integer.parseInt(sc.nextLine());
           if (n <= books){  
               books -= n;
               amount -= 200*n;
           }
           else{
               System.out.println("Yo do not have that much of books");
           }
       }  
   }
}

class main{
   public static void main(String[] args){
       BooksExpenses be = new BooksExpenses("Vijender",102,10,2000);
       be.BuymoreBooks();

   }
}