How To Create A Driver Program That Invokes A Class
May 13, 2014
Assignment:
Create a class; call it Lab4a that will have one method called pull. This method does not return anything and requires no parameters.
-In the method, create three random integers in the range 1 to 7. The method will then display the three numbers to the terminal window.
-Now create a driver program, called SlotMachine, to invoke the pull method of the Lab4a class.
-As a refresher, you will have a main method in the driver class that will create an object of Lab4a and then use the only method of this object.
-In your driver program, invoke the roll method 10 times.
-See the back of this lab for an example of the output.
This is what I have so far.
Slot machine
import java.util.Random;
public class Lab4a {
public static void main (String[]args) {
Random pull=new Random();
[code]....
View Replies
ADVERTISEMENT
Aug 17, 2014
I have a jsp page that has a url that looks like this
<p><a href="SubscriptionController?action=subscriptionlist">Administrator Subscription Maintenance List</a></p>
Now I want to essentially slide through that page by using jsp:forward instead of the link
<jsp:forward page="/SubscriptionController?action=subscriptionlist" />
Problem is, the link invokes the doGet method of my servlet and the jsp:forward invokes the doPost. Is it possible to use jsp:forward and specify doGet somehow?
View Replies
View Related
May 2, 2014
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?
View Replies
View Related
May 10, 2014
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);
[Code] ....
View Replies
View Related
Feb 20, 2014
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');
[code]....
View Replies
View Related
May 14, 2015
I came across the below
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.
View Replies
View Related
May 5, 2014
Okay, so I have to create a class with instance data and instance methods.
First, BankAccount class. It should contain the following information, stored in instance variables:
First name: The customer's first name.
Last name: The customer's last name
Balance: The amount of money the customer has in the account.
It should have the following methods:
BankAccount(String firstName, String lastName,
double openingBalance)
This constructor creates a new BankAccount
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) {
[Code] .....
View Replies
View Related
Apr 13, 2015
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) {
[Code] ...
View Replies
View Related
Oct 30, 2014
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()
[Code] ....
View Replies
View Related
Dec 6, 2014
I am trying to create a program for class the uses two dimensional arrays. I am stuck on the second step that states Use two parallel arrays. One is a two-dimensional array -- a row of this array will hold six values in this order: [0] number of hours worked, [1] hourly pay rate, [2] gross pay, [3] net pay, [4] federal withholding, and [5] state withholding.
This is what I have so far:
Java Code:
double [][] data = new double [30][6];
String [] names = new String [30];
String str = null;
String detail = null;
int n = input(data, names, inputFile); mh_sh_highlight_all('java');
(there's more but i don't believe it pertains to this question)
My question is how would I create this array. Or, is that right above? I've searched online and in my book and I just don't understand.
View Replies
View Related
Nov 18, 2014
I want to create java program in which i want to inherit stack and queue from a linked list class and also make infix to postfix inherit from stack and periority queue from queue class.Ho can i make this program.
View Replies
View Related
Feb 1, 2014
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;
[code].....
View Replies
View Related
Apr 22, 2015
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.
View Replies
View Related
Jun 10, 2014
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);
[code]....
View Replies
View Related
Jun 3, 2014
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;
[code]...
View Replies
View Related
Mar 16, 2014
i want create little program which enter the number, ant program says triangle exist or not. So code :
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
[code]...
So when i put first num like 1, next num like 2 and next num like 100 , program says Triangle exist.
View Replies
View Related
May 9, 2015
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;
[code]....
View Replies
View Related
Oct 3, 2014
How can one create a well-encapsulated class?What are the principles to be followed?
View Replies
View Related
Sep 25, 2013
Can I declare a class as
public static final?
Because I can declare a variable as public static final pi=3.14;
View Replies
View Related
Jul 18, 2014
Why we can't create object of abstract class ,when we can create its constructor?
View Replies
View Related
Dec 15, 2014
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.
View Replies
View Related
Feb 25, 2014
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("----------------------------------");
[Code]...
This is how I want my project to look like:
View Replies
View Related
Mar 17, 2015
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.
View Replies
View Related
Dec 11, 2012
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)?
View Replies
View Related
Jun 1, 2014
So I am making a JPanel with two JLabels and it isn't working right.
import java.awt.*;
import javax.swing.*;
public class IntroPanel extends JPanel
{
public IntroPanel() {
setBackground(Color.green);
[Code] ....
For some reason
JLabel 11 = new JLabel("Layout Manger Demonstration");
JLabel 12 = new JLabel ("Choose a tab to see an example of a layout manger.");
add(11);
add(12);
is not registering the JLabel or add functions.
View Replies
View Related
Jul 23, 2014
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;
[code]....
View Replies
View Related