Search This Blog

UI/UX Design | Web Development | Mobile Application Development

Whether you need UI/ UX design, web development services, or mobile app development services, Qaabil Digitals will be more than happy to help you. We work with top software developers, designers, and project managers. We tailor our services to suit your exact needs. We closely look at your company, listen to your story, and bring about the best ideas and solutions that can help you drive solid results. We don’t just produce work that works. We produce work that matters. Get a quote now Or Talk to us

Wednesday, 19 October 2011

Java program to display ifno of different cars using abstract class (by noor diana fauzi)

import java.util.*;
class CarPrice
{
public static void main (String args[])
{
Ford fr = new Ford();
fr.getcarmaker();
fr.setPrice();
Chevy ch = new Chevy();
ch.getcarmaker();
ch.setPrice();
fr.displyinfo();
ch.displyinfo();
}
}

abstract class Auto
{
abstract void getcarmaker();
abstract void setPrice();
}

class Ford extends Auto
{
Scanner in = new Scanner (System.in);
double price;
String maker;
void getcarmaker()
{
System.out.print ("\n\t Enter the name of car maker = ");
maker=in.nextLine();
}

void setPrice()
{
System.out.print ("\n\t Enter price of "+maker+" car = $");
price=in.nextDouble();
}

void displayinfo()
{
System.out.println ("\n\t Car maker = "+maker);
System.out.println ("\n\t Car Price = $"+price);
}
}

class Chevy extends Auto
{
Scanner in = new Scanner (System.in);
double price;
String maker;
void getcarmaker()
{
System.out.print ("\n\t Enter the name of car maker = ");
maker=in.nextLine();
}

void setPrice()
{
System.out.print ("\n\t Enter price of "+maker+" car = $");
price=in.nextDouble();
}

void displayinfo()
{
System.out.println ("\n\t Car maker = "+maker);
System.out.println ("\n\t Car Price = $"+price);
}
}

No comments:

Post a Comment

Share