creating java classes

Ads
 

creating java classes

This program uses a class named DrivingLicense to keep track of two driving licenses, including the driver?s name, and the number of speeding tickets they have received. You may not modify the DLTest code, but should write the DrivingLicense class, and test it using the DLTest.java program to ensure that it generates the following output.

Alice does NOT have a suspended license Bob does NOT have a suspended license Bob and Alice are both caught speeding! Alice has a suspended license! Bob does NOT have a suspended license

/* Class: DLTest.java Description:Test program for the DrivingLicense class

public class DLTest { // main() method public static void main(String[] args) { // declare and create two DrivingLicense objects DrivingLicense d1 = new DrivingLicense(); DrivingLicense d2 = new DrivingLicense();

    // initialize the objects with names and speeding tickets
    d1.name = "Alice";
    d1.numTickets = 2;

    d2.name = "Bob";
    d2.numTickets = 0;

    // check if Alice or Bob have suspended licenses (more than 2 tickets)
    if ( d1.isSuspended() )
    {
        System.out.println(d1.name + " has a suspended license!");
    }
    else
    {
        System.out.println(d1.name + " does NOT have a suspended license");
    }

    if ( d2.isSuspended() )
    {
        System.out.println(d2.name + " has a suspended license!");
    }
    else
    {
        System.out.println(d2.name + " does NOT have a suspended license");
    }

    // Alice and Bob both get caught speeding, so add another ticket for each of them
    System.out.println("Bob and Alice are both caught speeding!");
    d1.addTicket();
    d2.addTicket();

    // check again if Alice or Bob have suspended licenses (more than 2 tickets)
    if ( d1.isSuspended() )
    {
        System.out.println(d1.name + " has a suspended license!");
    }
    else
    {
        System.out.println(d1.name + " does NOT have a suspended license");
    }

    if ( d2.isSuspended() )
    {
        System.out.println(d2.name + " has a suspended license!");
    }
    else
    {
        System.out.println(d2.name + " does NOT have a suspended license");
    }

}

}

*/

View Answers

Ads









Related Tutorials/Questions & Answers:
creating java classes
creating java classes  Create a Java class that can be used to store inventory information about a book. Your class should store the book title... a program that tests your class by creating and using at least two objects of the class
creating java classes
creating java classes  This program uses a class named DrivingLicense to keep track of two driving licenses, including the driver?s name, and the number of speeding tickets they have received. You may not modify the DLTest code
Advertisements
Java list of uninstantiated classes
Java list of uninstantiated classes  Java list of uninstantiated classes
Creating a memory leak with Java
Creating a memory leak with Java  Creating a memory leak with Java
Classes in Java
Classes in Java      ... java have mechanisms for handling exceptions. This is known as catching exception in Java. The exceptions that occur in the program can be caught using try
GWT supported java classes
GWT supported java classes  What are the methods and classes in Java which are supported and unsupported by GWT
Collection classes in java
is the reason using java collection classes saved/stored the data/content.I don't understand, what is the idea using java collection classes in project. Or the data is stored in both database and java collection classes
Collection classes in java
is the reason using java collection classes saved/stored the data/content.I don't understand, what is the idea using java collection classes in project. Or the data is stored in both database and java collection classes
Creating objects for classes and calling functions of a dll file using JNI
Creating objects for classes and calling functions of a dll file using JNI .... In this file, some c++ classes and functions are available. How can we create objects for these classes and how can we call these functions by using JNI. Am
Helper classes in java
Helper classes in java  helper classes
Creating PDF in JAVA
Creating PDF in JAVA  How create pdf in java ? Take value from database for particular PDF
What is Abstract classes in Java?
What is Abstract classes in Java?  What is Abstrack class in Java...,   Hi, In Java programming language we are used the Java Abstract.... That's why the Abstract class in Java programming language is used to provide
Java application that uses the classes and
Java application that uses the classes and   i have this class diagram with three classes: Curriculum, Course, and Lecture. Your class diagram...) I wish Write a Java application that uses the classes and methods above
creating reports in java
creating reports in java  how to create reports automatically in java and send it via mail by scheduling tine for weekly,monthly basis
JAVA CLASSES/ SUPERCLASS
JAVA CLASSES/ SUPERCLASS  i. Define a class called Student and its two subclasses named underGraduateStudent and postGraduateStudent. Make a subclass of Employee. A person has a name, address, phone number, and email address
creating JAR - Java Beginners
creating JAR  I am beginner in J2ee.I am creating an application... installed SQL and Tomcat.I created a JAR of my java project and included in the library of web project. My problems 1. I added new class in the java project
Disassembling Java Classes - Java Tutorials
Disassembling Java Classes To Disassemble a class file in Java there is a tool... class of java. first compile them using javac then call the javap Class...:\Java Test>javac DisassesmleExample.java Now run it using javap as C:\Java
Creating URL in java
Creating URL in java  Hii to all I m trying to create a url using java. Address is http://www.merchant.com/pg/index.html When i m going to run...[] args) { try { // // Creating
creating packages in java
creating packages in java  Hi everybody, I am Rupesh Narayan, i faces a problem while creating package in core java. I write two programs that are described below:- 1.PackageDemo.java package javaclass; import java.io.*; public
java coding for creating table in the console
java coding for creating table in the console  write a java program to create table
Inner Classes In Java
Inner Classes In Java       There are 4 kind of classes that can be defined in a Java program, roughly can be termed as the inner classes. --  Inner classes provides an elegant
Java Classes
Java Classes conducted online by Roseindia include an elite panel of some... that if a beginner starts taking a Java classes online here, than he/she... an expert in the field. Java classes also act as libraries for future reference
What are Classes and Interfaces in Java?
In this tutorial we are going to discuss about classes and interfaces in Java... language. Anyone learning Java programming language should learn classes and interfaces concepts in detail. What are classes? Java is Object oriented
How are Anonymous (inner) classes used in Java?
How are Anonymous (inner) classes used in Java?  How are Anonymous (inner) classes used in Java
Member Classes, Inner Nested Classes in java
Member Classes        Member classes are defined within the body of a class. We can use member classes anywhere within the body of the containing class. We declare member classes
Java classes
Java classes are like a group under which all objects and methods... examples that will help beginners in Java understand the definition of Java classes... of Java classes, object and its methods. Here in order to determine Area
Creating Excel sheets - Java Beginners
Creating Excel sheets  Hi, I want the java code for creating excels sheets with two workbooks using POI, and to find the difference between the particular value of one cell and others. asuming the contents of teh files adn
executing java program with 2 classes
); } }   Executing java program with 2 classes save the file with D.java...executing java program with 2 classes  how to run a program of java containing more than one class....ex of program is given below.... class C
File Handling Classes in Java
In this section, you will get to know about file handling classes in java to handle the file input output operations
Video Tutorial - Classes and Objects in Java
Video Tutorial on Classes and Objects in Java teaches you with example code In this video tutorial you will learn about Classes and Objects in Java... will learn what are Classes and Objects in Java program. You will also learn how
Distinguishes JavaBeans from Java Classes
Distinguishes JavaBeans from Java Classes  What is the difference between a Java Bean and an instance of a normal Java class?Explain with an example, pls?   Hi Friend, Differences: 1)The java beans are serializable

Ads