Why we create a driver class?Instead of creating a driver class, if we want to compile our code so will it show output? Let say, we've created a class GradeBook of the institution for students.So they can easily view their profile information and scores in different semesters.so when we have created a class for this purpose, should we create a driver class or not?What is the big advantage of creating a driver class?
I am having trouble creating a driver for the following program. im new to creating interfaces and i need to make this work.
Lockable interface:
Java Code:
public interface Lockable { boolean locked(); public void setKey(int key); public void lock(int key); public void unlock(int key); } mh_sh_highlight_all('java');
1) When a variables are declared "Private" How should it be accessed from the driver class ? Sometimes i get an error in driver class saying "your variable is declared Private" why am I getting this error ...
The document says "Private" declared variables should be accessed only through methods. What does that mean.
public class Car { //instance variables ---------------------- private String make; private String model; private int year; private double vehiclePrice; private double downPayment; private double milesPerGallon;
[code]....
I created this class "Car" (also not sure if it's correct) and need to write a driver program that creates two instances of the class Car. One must use the default constructor, and the other must use the non-default constructor. It must demonstrate the methods used in the Car class using those instances.
public class DriverCar { public static void main(String[] args) { Car car1 = new Car("Toyota", "Corolla", 2013, 20000, 3000, 35); Car car2 = new Car("Ford", "Taurus", 2005, 14000, 1500, 25); System.out.println(car1);
public String firstName() Returns the customer's first name public String lastName() Returns the customer's last name public double balance() Returns the customer's account balance
Finally I need to create a driver to test my class. And create several accounts and verify that the first name, last name, and balance methods work properly. This is my code below.. I don't know if I did it right.
public class BankAccount { String firstName, lastName; double balance; public BankAccount(String firstName, String lastName, double balance) {
I am to create a Array class then create a Driver class (TestArray) to test all the methods in the Array Class. Here's the code i've written for the Array Class. I just nee developing the TestArray class.
import java.util.Scanner; public class Array { Scanner sc = new Scanner(System.in); private double[] array = new double[]; public void setArray(double[] arr) {
I have a driver and a main program. How would I go along with calling the encode method to the driver class that I made so I can have the user inputs affected by the encode method?
Java Code:
public class ShiftEncoderDecoder { private int shift; public ShiftEncoderDecoder(int shift) { setShift(shift); } public int getShift()
In the class below I'm trying to create a class that will accept dates in various formats and create a range. The first constructor is easy because I send it the begin date and end date as Date objects. Now I want to send a month(and year) in a constructor and derive the begin and end dates from it. In my constructor that accepts the month/year I need to put the this(startDate, endDate) at the top to be allowed, but the parameters are not built yet.
package com.scg.athrowaway; import java.util.Calendar; import java.util.Date; public class DateRange { private Date startDate; private Date endDate;
How to create object for "class B" and call the "function_B" from other different class D where class D has no connection with class A? Here is my program.
public class A(){ void print(){} } class B{ void function_B(){} } class C{ void function_C(){} }
Here, A, B, C are in the same package. But class D is in different package.
Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. There is also a MyDate class as explained below. A person has a name, address, phone number, and email address. A student has a status (freshman, sophomore, junior, or senior). Define the status as an integer which can have the value 0 (for "Freshman"),
1 (for "Sophomore"), 2 (for "Junior"), and 3 (for "Senior"),
but don't allow the status to be set to any other values. An employee has an office, salary, and dateHired. The dateHired is a MyDate field, which contains the fields: year, month, and day. The MyDate class does not explicitly inherit from any class, and it should have a no-arg constructor that sets the year, month, and day to the current year, month, and day. The MyDate class should also have a three-argument constructor that gets three int arguments for the year, month and day to set the year, month and day.
A faculty member has office hours and a rank. Define the rank as a String (for values like "Professor" or "Instructor"). A staff member has a title, which is also a String. Use data types for the fields as specified, or where one is not specified, use a data type that is appropriate for the particular field. Write a test program called TestEveryone.java that creates a Person, Student, Employee, Faculty, and Staff object, and invoke their toString() method (you don't need to call the objects' toString() method explicitly).
Note: Your MyDate.java class is the object class that your dateHired field is created from in the Employee.java class.
Do not use the Person, Employee or Faculty classes defined on pages 383 and 384 of the book. Create new ones.Here is the code I have so far concerning the employee and MyDate.
public class Employee extends Person { private String office; private double salary; //private MyDate dateHired; //7 argument constructor for employee public Employee(String name, String phoneNumber, String email, String address, String office, double salary /*MyDate dateHired*/) { super(name, phoneNumber, email, address);
The assignment is to create a SmartString class that implements a SmartStringInterface class (created by professor) and implements a few methods. We are basically taking a string and then taking various substrings and inserting, deleting them and undoing changes as well. Here are the methods in the interface to use along with the parameters.
public interface SmartStringInterface { public void insert(int pos, String sstring); public void delete(int pos, int count); public void undo(); public String toString();
The Undo is supposed to be able to be called multiple times (to be tested using a driver program that we must create) but the part that's got me is that the changes are only supposed to be stored. Currently, I am storing the "new" string after each change onto a stack, so that undo can just pop off the stack and it will revert to the previous string. Professor said that was wrong, so I don't know how to do it. Here is what I have so far (some of the code we have is using default StackADT stuff from our book, so if you need that I can post as well. You can see in the undo method where I currently save the string. We can use multiple stacks if needed, but the less the better. Must use at least 1. The exception code is already coded for us in another file also. I am only having to code these methods and the driver to test.
import java.util.Arrays; public class ArrayStack<T> implements StackADT<T> private final static int DEFAULT_CAPACITY = 100 private int top; private T[] stack;
I'm new to Java and I have an assignment to create a Sphere class that will allow you to create Sphere objects using the code below. Then create a program called SphereTester that prompts the user for the radii of two spheres in meters. The program should display which sphere is larger and by how many cubic meters and display only four digits after the decimal point. I have the sphere class given to us for the assignment which is this:
Java Code: public class Sphere { // instance variable (i.e., a field) private double radius; // constructor for the Sphere class public Sphere(double r) { radius = r;
I'm trying to get to grips with the AndEngine, so I've recently gotten hold of their Cookbook, but there's a section that's confusing. I'm using the Eclipse IDE with the section is asking that I create two inner classes to an ObjectFactory class. I'm not sure if what it wants me to do is doable in java or specifically in Eclipse. This is the section of code the book is asking me to create.
Java Code:
package com.example.helloworld;
public class ObjectFactory { public static LargeObject createLargeObject(final int pX, final in pY){ return new LargeObject(pX,pY); } public static SmallObject createLargeObject(final int pX, final in pY){ return new SmallObject(pX,pY); } } mh_sh_highlight_all('java');
Now this is returning errors that I should declare these two as individual classes, but I feel like I am missing something. Earlier the book asks you to create this BaseObject class.
Java Code:
package com.example.helloworld;
public class BaseObject { @SuppressWarnings("unused") private int mX; @SuppressWarnings("unused") private int mY;
[code]...
It then mentions that the two classes LargeObject and SmallObject are inner classes of BaseObject and extends this class. The ObjectFactory class is meant to determine which subtype of the base class that needs, as well as define the objects properties.
I want to create a class that converts currency. I stored 2 conversion rate as constant (final) variables. In the main method, I ask the user to enter the amount in US dollars that they want to convert. Then I ask the user to enter the currencyType ("Bitcoin" or "Chuck E Cheese").
However I am stuck in the while loop:
I want to use a while loop that basically does this: If the user entered anything else ( not Bitcoin or Chuck E Chesse), then tell the user to try again, and keep reading Strings until they enter a correct currency type. If the user 3 consecutive incorrect currency types, then exit the program.
Take a look at what I have so far.. when I run the program it does not quite do what I want it to do Also, there's something wrong with one of my if statements and I want to figure out how to fix it.
Java Code:
import java.util.Scanner; public class CurrencyConverter { public static void main(String[] args) { System.out.println("----------------------------------"); System.out.println(" Currency Converter"); System.out.println("----------------------------------");
I'm new to java and trying to learn the ropes on Netbeans!What I want to do is make a class which does the following
-Asks for and reads a first number on the command line. -Asks for and reads a second number using a JOptionPane -Asks for and reads your name using a JOptionPane
I want it to output the name and the remainder of the first number divided by the second number.
I know that System is a final class and it cannot be instantiated, out is a static final variable of type PrintStream in System class and println is a method in PrintStream class.Still I don't understand why we use System.out to call println() method.To my knowledge a method can be called using an object reference, in case of static behaviors we use classname. Then why here we are using System.out.println? Can't we just create an object of PrintStream class and call the println() method as PrintStream class can be instantiated.Are there any ways of calling a method apart from those I know(I have mentioned above what I know)?
I'm learning about abstract classes and I have to create an abstract auto class with make and price of a car, then two classes with a different type of car, and finally a main to use them. Everything seems to work and when I run it it's fine but I do get an error on the main that I'm not using the local variable buick1 and acura1.I'm curious because, while it runs for me, I want to make sure I'm doing it right and don't know of another way to do the output than this. I've put all four classes but the issue is on the last one (5 and 7).
public abstract class Auto { protected String makeCar; protected double priceCar; public Auto(String newMake) { makeCar = newMake;
I have an assignment to create a Sphere class that will allow you to create Sphere objects using the code below. Then create a program called SphereTester that prompts the user for the radii of two spheres in meters. The program should display which sphere is larger and by how many cubic meters and display only four digits after the decimal point. I have the sphere class given to us for the assignment which is this:
public class Sphere { // instance variable (i.e., a field) private double radius; // constructor for the Sphere class public Sphere(double r) { radius = r;
[code]....
Here is a sample run of what the final result should look like
Enter the radius of a sphere (in meters): 1 Enter the radius of a 2nd sphere (in meters): 2 Sphere 2 is greater than Sphere 1 by 29.3215 cubic meters
I know that we can create an inner class inside an interface but i want to know that why we'll create an inner class inside an interface. I mean what is the use of creating inner class inside an interface and what is the advantage of it.