How can help me to create this program?
PartADriver
public class PartADriver
{
public static void main (String [] args)
{
// create two martians
Martian m1 = new Martian();
Martian m2 = new Martian("Grey", 3);
// display both martians
Output.showMessage("After instantiation.\n" +
"Martian #1: " + m1.toString() +
"\nMartian #2: " + m2.toString());
// make the first martian speak 3 times
for (int count = 0; count < 3; count++)
m1.speak();
// make the second martian speak once
m2.speak();
// display both martians
Output.showMessage("After speaking.\n" +
"Martian #1: " + m1.toString() +
"\nMartian #2: " + m2.toString());
// try some other methods
m1.setName("Martin");
m2.setNumLegs(7);
Output.showMessage("After calling some setters.\n" +
"Martian #1: " + m1.toString() +
"\nMartian #2: " + m2.toString());
if (m1.getNumLegs() > m2.getNumLegs())
Output.showMessage(m1.getName() + " has the most
legs.");
else
Output.showMessage(m2.getName() + " has the most
legs.");
} // method main
} // class PartADriver
Here i hvae create two class Martian and PartADriver
Code for partadriver project
package partadriver;
//class Martian
class Martian
{
//class variable
String Name;
int Legs;
int speackcount;//for counting speak
//defualt constractor
Martian()
{
speackcount=0;
}
//perameterize constractor
Martian(String name,int numLegs)
{
Name=name;
Legs=numLegs;
speackcount=0;
}
//get name
public String getName()
{
return Name;
}
//get number of legs
public int getNumLegs()
{
return Legs;
}
//set name
public String setName(String name)
{
this.Name=name;
return Name;
}
//set number of legs
public int setNumLegs(int numLegs)
{
this.Legs=numLegs;
return Legs;
}
//method speak
public void speak()
{//if even
if(speackcount%2==0)
{
System.out.println(Name+" says: Burble!");
}
//else odd
else
{
System.out.println(Name+" says: Take me to your leader!");
}
speackcount++;
}
//to string
public String toString()
{
return "name"+Name+" Legs"+Legs;
}
}
public class PartADriver
{
public static void main(String[] args)
{
// create two martians
Martian m1 = new Martian();
Martian m2 = new Martian("Grey", 3);
m1.setName("Blue");
m1.setNumLegs(2);
// display both martians
System.out.println("After instantiation.\n" +
"Martian #1: " + m1.toString() +
"\nMartian #2: " + m2.toString());
// make the first martian speak 3 times
for (int count = 0; count < 3; count++)
m1.speak();
// make the second martian speak once
m2.speak();
// display both martians
System.out.println("After speaking.\n" +
"Martian #1: " + m1.toString() +
"\nMartian #2: " + m2.toString());
// try some other methods
m1.setName("Martin");
m2.setNumLegs(7);
System.out.println("After calling some setters.\n" +
"Martian #1: " + m1.toString() +
"\nMartian #2: " + m2.toString());
if (m1.getNumLegs() > m2.getNumLegs())
System.out.println(m1.getName() + " has the most legs.");
else
System.out.println(m2.getName() + " has the most legs.");
}
}
Output:
Thank you if you have any query regarding above answer please ask me in comment box.
if you like my work appreciate with thums up.
Thank You.
How can help me to create this program? PartADriver public class PartADriver { public static...
Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...
Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super class. The class includes four private String instance variables: first name, last name, social security number, and state. Write a constructor and get methods for each instance variable. Also, add a toString method to print the details of the person. After that create a class Teacher which extends the class, Person. Add a private instance variable to store number of courses. Write a constructor...
Need help to create general class Classes Data Element - Ticket Create an abstract class called Ticket with: two abstract methods called calculateTicketPrice which returns a double and getld0 which returns an int instance variables (one of them is an object of the enumerated type Format) which are common to all the subclasses of Ticket toString method, getters and setters and at least 2 constructors, one of the constructors must be the default (no-arg) constructor. . Data Element - subclasses...
Java Create four classes: 1. An Animal class that acts as a superclass for Dog and Bird 2. A Bird class that is a descendant of Animal 3. A Dog class that is a descendant of Animal 4. A “driver” class named driver that instantiates an Animal, a Dog, and a Bird object. The Animal class has: · one instance variable, a private String variable named name · a single constructor that takes one argument, a String, used to set...
Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML 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 . 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 . Getters and setters: get Name (), getEmail() and getGender (). There are no setters for name and...
JAVA Create a Java project to implement a simple Name class. This class will have the following class variable: First Name, Middle Name, Last Name, and Full Name Create the accessor/getter and mutator/setter methods. In addition to these methods, create a toString() method, which overrides the object class toString() method. This override method prints the current value of any of this class object. Create a main() method to test your project.
JAVA /** * This class stores information about an instructor. */ public class Instructor { private String lastName, // Last name firstName, // First name officeNumber; // Office number /** * This constructor accepts arguments for the * last name, first name, and office number. */ public Instructor(String lname, String fname, String office) { lastName = lname; firstName = fname; officeNumber = office; } /** * The set method sets each field. */ public void set(String lname, String fname, String...
Create a UML diagram to help design the class described in exercise 3 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Baby class object; should they be private or public? Determine what class methods are required; should they be private or public? Write Java code for a Baby class. A Baby has a name of type String and an age of type integer. Supply two constructors:...
Please help me with this Java problem. Would greatly appreciate comments in the code as well: Define a class called Counter whose internal "count" variable is a basic integer counter. This class track that count from its instantiation in the constructor (can be set to any positive integer, or 0). The count should never be allowed to be negative. Include methods that will set the counter to 0, increase the count by 1, and decrease the count by 1. Include...
In this assignment you will create two Java programs: The first program will be a class that holds information (variables) about an object of your choice and provides the relevant behavior (methods) The second program will be the main program which will instantiate several objects using the class above, and will test all the functions (methods) of the class above. You cannot use any of the home assignments as your submitted assignment. Your programs must meet the following qualitative and...