5. Design a class for a book that an online retailer (such as Amazon.com) might
ID: 662839 • Letter: 5
Question
5. Design a class for a book that an online retailer (such as Amazon.com) might use
to keep track of the book. Fields might include name of the book, publisher, price,
author, and ISBN. Think about the methods appropriate for the class that an
online retailer might use.
6. Consider a hospital scenario. Design classes for:
Patients. The class might have elds like unique ID for the patient, name,
male or female, age, address, phone number, date of birth, height, and weight.
Doctor. Fields might include the doctor's name, unique registration number,
quali cation (DO or MD), specialization (surgeon, pediatrician, etc.), phone
number, oce hours, and oce location.
Patients' records in a hospital. The record might have elds like last date of
checkup, doctor's unique ID, patient's unique ID, list of health problems in
the patient, list of medicines prescribed, cost of the checkup, nal report, and
so on.
Methods of these classes would be mostly get and set methods for the corresponding
elds.
7. Design a class called Color. The elds of the class are three decimals for Red,
Green, and Blue components in the range 0 to 1, inclusive (0 indicates Black and
1 indi- cates White). Add checks to ensure that the values are always in the given
range. Provide addition and subtraction operators for the color class. Include
saturation in the addition and subtraction: if any component goes less than 0 or
greater than 1, assign them 0 or 1, respectively.
Explanation / Answer
1.
Book.java
public class Book extends Product
{
String author=null;
String isbn=null;
String publisher=null;
public Book(String name, String desc, double price, String author,
String isbn, String publisher)
{
super(name,desc,price);
this.author = author;
this.isbn = isbn;
this.publisher = publisher;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getIsbn() {
return isbn;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
public String getPublisher() {
return publisher;
}
public void setPublisher(String publisher) {
this.publisher = publisher;
}
}
product.java
import javax.persistence.Id;
public class Product
{
long id;
String name = null;
String description = null;
double price = 0.0;
protected Product()
{
}
public Product(String name, String desc, double price)
{
this.name = name;
this.description = desc;
this.price = price;
}
2.
patient.java
import java.util.LinkedList;
public class Patient extends User {
private int PatientiD;
private int age;
private String birthDate;
private double weight;
private double height;
private int bmi;
private String type;
private LinkedList<String> doctorSugestions;
public Address pAddress;
public Patient(int i, String email, String fName, String lName, String password, String hint,
Address p) {
super(i, email, fName, lName, password, hint, "Patient");
this.age = 0;
this.birthDate = "";
this.weight = 0;
this.height = 0;
this.bmi = 0;
this.type = "Patient";
this.pAddress = p;
this.doctorSugestions = new LinkedList<String>();
}
Patient( Patient p){
this.setID(p.getID());
this.setEmail(p.getEmail());
this.setFirstName(p.getFirstName());
this.setLastName(p.getLastName());
this.setPassword(p.getPassword());
this.setHint(p.getHint());
this.setType(p.getType());
this.PatientiD = p.PatientiD;
this.age = p.age;
this.birthDate = p.birthDate;
this.weight = p.weight;
this.height = p.height;
this.bmi = p.bmi;
this.type = "Patient";
this.pAddress = p.pAddress;
this.doctorSugestions = p.doctorSugestions;
}
public Patient(int a, String bD, double w, double h, int bmi){
this.age = a;
this.birthDate = bD;
this.weight = w;
this.height = h;
this.bmi = bmi;
this.type = "Patient";
}
public Patient() {
this.PatientiD = 0;
this.age = 0;
this.birthDate = "";
this.weight = 0;
this.height = 0;
this.bmi = 0;
this.type = "Patient";
this.pAddress = null;
this.doctorSugestions = new LinkedList<String>();
}
public String toString(){return (super.toString() + " " + age + " "+ birthDate + " "+ weight + " "+ height + " "+ bmi + " "+ pAddress.toString()); }
public void addSuggestion(String d){this.doctorSugestions.add(d);}
public int getAge() { return age; }
public String getBirthday() { return birthDate; }
public double getWeight() { return weight; }
public double getHeight() { return height; }
public int getBMI() {return bmi;}
public int getPatientID(){return PatientiD;}
public Address getAddress(){return this.pAddress;}
public String getType(){ return type;}
public void setAge(int a) { this.age = a; }
public void setBirthDate(String bD) { this.birthDate = bD;}
public void setWeight(double w) { this.weight = w; }
public void setHeight(double h) {this.height = h;}
public void setBMI(int bmi) { this.bmi = bmi; }//needs an algorithm
public void setPatientID(int i){this.PatientiD = i;}
}
user.java
public class User {
private int iD;
private String accountType;
private boolean authenticated;
private String email;
private String firstName;
private String lastName;
private String encryptedPassword;
private String hint;
public User(int i,String email, String fName, String lName, String password, String h, String acc){
this.iD = i;
this.email = email;
this.accountType = acc;
this.encryptedPassword = password;
this.hint = h;
this.firstName = fName;
this.lastName = lName;
this.authenticated = false;
}
public User(String user, String password , String acc){
this.email = user;
this.encryptedPassword = password;
this.accountType = acc;
}
public User(){
this.iD = 0;
this.email = "";
this.accountType = "";
this.encryptedPassword = "";
this.hint = "";
this.firstName = "";
this.lastName ="";
this.authenticated = false;
}
public String toString(){return (accountType + " " + iD +" "+ email + " "+ encryptedPassword + " "+ firstName + " "+ lastName + " "+ hint);}
public String getEmail(){ return email;}
public String getType(){ return accountType;}
public String getFirstName(){ return firstName;}
public String getLastName(){ return lastName;}
public String getPassword(){ return encryptedPassword;}
public String getHint(){return hint;}
public boolean getAuthenticate(){ return authenticated;}
public int getID(){return iD;}
public void setPassword(String password){ this.encryptedPassword = password;}
public void setType(String type){this.accountType = type;}
public void setEmail(String email){ this.email = email;}
public void setFirstName(String fName){ this.firstName = fName;}
public void setLastName(String lName){ this.lastName = lName;}
public void setHint(String hint){this.hint = hint;}
public void setAuthenticate(boolean authenticate){ this.authenticated = authenticate;}
public void setID(int i){this.iD = i;}
}
Doctor.java
import java.util.LinkedList;
public class Doctor extends User {
private String suggestions;
private LinkedList<Patient> patientList;
public Doctor() {
this.suggestions = "";
this.patientList = new LinkedList<Patient>();
}
public Doctor(int i, String email, String fName, String lName, String password, String hint
) {
super(i, email, fName, lName, password, hint, "Doctor");
this.suggestions = "";
this.patientList = new LinkedList<Patient>();
}
public String toString(){
return patientList.toString();
}
public String getSugesstion(){return suggestions;}
public void addSugesstion(String s){this.suggestions = this.suggestions + " " + s ;}
public void setPatient( Patient p){ this.patientList.add(p);}
}
3.
ColorTesting.java
import aws.color.toolbox.AWSColorToolbox;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.HeadlessException;
import javax.swing.JComponent;
import javax.swing.JFrame;
public class ColorTesting extends JFrame{
public ColorTesting() throws HeadlessException
{
setMinimumSize(new Dimension(1800,1024));
createColorComponent();
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
repaint();
setVisible(true);
}
private void createColorComponent()
{
JComponent colorComponent = new JComponent() {
@Override
public void paint(Graphics g)
{
// draw the different blend modes in squares
//g.setColor(Color.green);
g.setColor(AWSColorToolbox.blendAddition(Color.green, Color.blue));
g.fillRect(0, 0, 500, 500);
g.setColor(AWSColorToolbox.blendDifference(Color.green, Color.blue));
g.fillRect(50, 50, 400, 400);
g.setColor(AWSColorToolbox.blendSimpleEqually(Color.green, Color.blue));
g.fillRect(100, 100, 300, 300);
g.setColor(AWSColorToolbox.blendSubtraction(Color.green, Color.blue));
g.fillRect(150, 150, 200, 200);
g.setColor(AWSColorToolbox.blendDifference(Color.green, Color.blue));
g.fillRect(200, 200, 100, 100);
g.setColor(AWSColorToolbox.blendAddition(Color.blue, Color.green));
g.fillRect(0+500, 0, 500, 500);
g.setColor(AWSColorToolbox.blendDifference(Color.blue, Color.green));
g.fillRect(50+500, 50, 400, 400);
g.setColor(AWSColorToolbox.blendSimpleEqually(Color.blue, Color.green));
g.fillRect(100+500, 100, 300, 300);
g.setColor(AWSColorToolbox.blendSubtraction(Color.blue, Color.green));
g.fillRect(150+500, 150, 200, 200);
g.setColor(AWSColorToolbox.blendDifference(Color.blue, Color.green));
g.fillRect(200+500, 200, 100, 100);
// draw the blending boxes
for(int i = 0 ; i <=250 ; i++)
{
g.setColor(AWSColorToolbox.blendSimpleByAmt(Color.red, Color.blue, (double)i/(double)250));
g.fillRect(0+i, 500+i, 250*2-(2*i), 250*2-(2*i));
g.setColor(AWSColorToolbox.invert(g.getColor()));
g.fillRect(500+i, 500+i, 250*2-(2*i), 250*2-(2*i));
}
// create the color box
Color[][] colorPic = new Color[518][518];
int col = 0;
for(int i = 0 ; i <=255 ; i+=3)
{
for(int k = 0 ; k < 518 ; k++) colorPic[col][k] = new Color(255,0,i);
col++;
}
for(int i = 255 ; i >=0 ; i-=3)
{
for(int k = 0 ; k < 518 ; k++) colorPic[col][k] = new Color(i,0,255);
col++;
}
for(int i = 0 ; i <=255 ; i+=3)
{
for(int k = 0 ; k < 518 ; k++) colorPic[col][k] = new Color(0,i,255);
col++;
}
for(int i = 255 ; i >=0 ; i-=3)
{
for(int k = 0 ; k < 518 ; k++) colorPic[col][k] = new Color(0,255,i);
col++;
}
for(int i = 0 ; i <=255 ; i+=3)
{
for(int k = 0 ; k < 518 ; k++) colorPic[col][k] = new Color(i,255,0);
col++;
}
for(int i = 255 ; i >=0 ; i-=3)
{
for(int k = 0 ; k < 518 ; k++) colorPic[col][k] = new Color(255,i,0);
col++;
}
// draw the color box
for(int i = 0 ; i <518 ; i++)
{
for(int j = 0 ; j <518 ; j++)
{
g.setColor(colorPic[i][j]);
g.fillRect(1000+i, 0+j, 1, 1);
}
}
// create the black to white box
Color[][] blackWhite = new Color[518][518];
col = 0;
for(double i = 0 ; i <=255 ; i+= 1/1.99999)
{
for(int k = 0 ; k < 518 ; k++) blackWhite[k][col] = new Color((int)i,(int)i,(int)i);
col++;
}
// draw the black to white box
for(int i = 0 ; i <518 ; i++)
{
for(int j = 0 ; j <518 ; j++)
{
g.setColor(blackWhite[i][j]);
g.fillRect(1000+i, 518+j, 1, 1);
}
}
// draw the blending
for(int i = 0 ; i <518 ; i++)
{
for(int j = 0 ; j <518 ; j++)
{
g.setColor(AWSColorToolbox.blendDifference(colorPic[i][j], blackWhite[i][j]));
g.fillRect(1518+i, 0+j, 1, 1);
g.setColor(AWSColorToolbox.blendExclusion(colorPic[i][j], blackWhite[i][j]));
g.fillRect(1518+i, 518+j, 1, 1);
}
}
}
};
colorComponent.setMinimumSize(new Dimension(1800,400));
colorComponent.repaint();
add(colorComponent);
}
}
@Id
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.