I have a java class that i need to rewrite in python. this is what i have so far:
class Publisher:
__publisherName=''
__publisherAddress=''
def __init__(self,publisherName,publisherAddress):
self.__publisherName=publisherName
self.__publisherAddress=publisherAddress
def getName(self):
return self.__publisherName
def setName(self,publisherName):
self.__publisherName=publisherName
def getAddress(self):
return self.__publisherAddress
def setAddress(self,publisherAddress):
self.__publisherAddress=publisherAddress
def toString(self):
and here is the Java class that i need in python:
public class Publisher {
//Todo: Publisher has a name and an address.
private String name;
private String address;
public Publisher(String name){
//Todo: #1: initialize attributes. Address should be set to the
string 'unknown'
// reuse as much as possible.
this.name = name;
this.address = "unknown";
}
public Publisher(String name, String address){
//Todo: #2: initialize attributes
this.name = name;
this.address = address;
}
public String getName() {
//Todo: #3
return name;
}
public void setName(String name) {
//Todo: #4
this.name = name;
}
public String getAddress() {
//Todo: #5
return address;
}
public void setAddress(String address) {
//Todo: #6
this.address = address;
}
/**
* The toString method converts an object to a string. It is used to
display the object in a println call.
* @return
*/
public String toString(){
//Todo: #7. Should show "Publisher '<name>' at
'<address>'"
return String.format("Publisher '%s' at '%s'",name,address);
}
}
class Publisher: def __init__(self, name, address='unknown'): self._name = name self._address = address def get_name(self): return self._name def get_address(self): return self._address def set_name(self, name): self._name = name def set_address(self, address): self._address = address def __str__(self): return "Publisher '%s' at '%s'" % (self._name, self._address) p = Publisher('ronaldo', 'portugal') print(p)
I have a java class that i need to rewrite in python. this is what i...
How to create a constructor that uses parameters from different classes? I have to create a constructor for the PrefferedCustomer class that takes parameters(name, address,phone number, customer id, mailing list status, purchase amount) but these parameters are in superclasses Person and Customer. I have to create an object like the example below....... PreferredCustomer preferredcustomer1 = new PreferredCustomer("John Adams", "Los Angeles, CA", "3235331234", 933, true, 400); System.out.println(preferredcustomer1.toString() + "\n"); public class Person { private String name; private String address; private long...
write comments // on this program please //Inside package bloodDonation //BloodDonor.java class package bloodDonation; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Scanner; public class BloodDonor { long idNumber, cardNumber; String name, bloodGroup, homePhone, mobilePhone, address, lastDateOfDonation; SimpleDateFormat myFormat = new SimpleDateFormat("dd MM yyyy"); public BloodDonor(){ this.idNumber = 0; this.cardNumber = 0; this.name = ""; this.bloodGroup = ""; this.homePhone = ""; this.mobilePhone = ""; this.address = ""; ...
Java. Java is a new programming language I am learning, and so far I am a bit troubled about it. Hopefully, I can explain it right. For my assignment, we have to create a class called Student with three private attributes of Name (String), Grade (int), and CName(String). In the driver class, I am suppose to have a total of 3 objects of type Student. Also, the user have to input the data. My problem is that I can get...
How to solve this problem? Consider the following class : public class Store Public final double SALES TAX_RATE = 0.063B private String name; public Store(String newName) setName ( newName); public String getName () { return name; public void setName (String newName) { name = newName; public String toString() return "name: “ + name; Write a class encapsulating a web store, which inherits from Store. A web store has the following additional attributes: an Internet Address and the programming language in...
4. Command pattern //class Stock public class Stock { private String name; private double price; public Product(String name, double price) { this.name = name; this.price = price; } public void buy(int quantity){ System.out.println(“BOUGHT: “ + quantity + “x “ + this); } public void sell(int quantity){ System.out.println(“SOLD: “ + quantity + “x “ + this); } public String toString() { return “Product [name=” + name + “, price=” + price + “]”; } } a. Create two command classes that...
JAVA help Create a class Individual, which has: Instance variables for name and phone number of individual. Add required constructors, accessor, mutator, toString() , and equals method. Use array to implement a simple phone book , by making an array of objects that stores the name and corresponding phone number. The program should allow searching in phone book for a record based on name, and displaying the record if the record is found. An appropriate message should be displayed if...
JAVA How to add array to develop a contact list application for the person class objects developed in this code? The application will include functionality to add, remove, sort and search the contact list. You should also include a method to output the contents of a contact searched for, and also to output the entire list. The code: package BankProg; public class personal { private String facebook; public personal() { } public personal(String facebook) { this.facebook...
write a parent class that describes a parcel (like a package, as shown below) and a child class that describes an overnight parcel. Use the provided Address class. A parcel is described by: id (which might contain numbers and letters) weight (described as the number of pounds; a parcel could be less than 1 pound) destination address (uses the provided class) An overnight parcel is described by id, weight, destination address and also: whether or not a signature is required...
GIVEN CODES *****Boat.java***** import java.util.HashSet; import java.util.Set; public class Boat { private String name; //private instance variable name of type String private String boatClass; //private instance variable boatClass of type String private int regNum; //private instance variable regNum of type int private Set<String> crew = new HashSet<String>(); public void setName(String name) { this.name = name; } public void setBoastClass(String boatClass) { this.boatClass = boatClass; } public void setRegNum(int regNum) { this.regNum = regNum; } public String getName() { return name;...
in javaA class called Author is designed as shown in the class diagram. Author name: String email: String gender: char +Author (name :String, email: String, gender char) +getName ():String +getEmail() String +setEmail (email: String) :void +getGender(): char +toString ():String It contains Three private instance variables: name (String), email (String), and gender (char of either 'm' or 'f), One constructor to initialize the name, email and gender with the given values; public Author (String name, String email, char gender) f......) public getters/setters: getName(), getEmail setEmail and getGender(); (There are no setters for name and gender,...