Define a class memberType which its object can hold the name of a person, member
ID: 3579962 • Letter: D
Question
Define a class memberType which its object can hold the name of a person, member identification, number of books bought and amount spent. a. Include the member functions to perform the various operations on the objects of membertype - for example, modify, set, and show a person's name. Similarly, update, modify, and show the number of books bought and the amount spent. b. Add the appropriate constructors c. Write the definitions of the member functions of memberType. d. Write a program to test various operations of your class memberType.Explanation / Answer
import java.util.*;
import java.lang.*;
import java.io.*;
class memberType
{
private String name;
private int ID;
private int books;
private double amount;
public memberType() //default constructor
{
this.name = " ";
this.ID = 0;
this.books = 0;
this.amount = 0.0;
}
public memberType(String name,int ID,int books,double amount) //parameterized constructor
{
this.name = name;
this.ID = ID;
this.books = books;
this.amount = amount;
}
public void setName(String name) //set and get methods
{
this.name = name ;
}
public String getName()
{
return name;
}
public void setBooks(int books)
{
this.books = books;
}
public int getBooks()
{
return books;
}
public void setAmount(double amount)
{
this.amount = amount ;
}
public double getAmount()
{
return amount;
}
public void setID(int ID)
{
this.ID =ID;
}
public int getID()
{
return ID;
}
}
class TestMemberType
{
public static void main (String[] args)
{
memberType m = new memberType("John Smith",100678,5,400.5);
System.out.println("Membership details : Name : "+m.getName()+" ID : "+m.getID()+" Books bought : "+m.getBooks()+" Amount Spent : "+m.getAmount());
}
}
output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.