Anda di halaman 1dari 12

A factory manufactures television sets.

A television produced by this


factory has the following buttons on it.
Power button
Channel Increase Button
Channel Decrease Button
Volume Increase Button
Volume Decrease Button
A Show Channel Button to display the current channel number
A Show Volume Button to display the current volume status.
Model above factory with the help of a class Television. Represent
on/off,volume and channel circuits with data members of type int.
Circuits can not be accessed directly by the users(all private).
All buttons should be represnted with the help of public functions.
also add a constructor to initialize all the data members to 0.
Creat two objects of this class type(purchase the television set from
this factory), push the power button of one television , increase its
channel and then push the show channel button to see the current
channel number.
Repeat these steps for second television.
class Television
{
int status;
int volume;
int channel;

Television( ){status=0; volume=0;channel=0;


}
void power()
{
if(status==0)
status=1;
else
status=0; }
void increaseVolume()
{ if(status==1)
volume++;
}
void increaseChannel()
{ if(status==1)
channel++;
}
void decreaseChannel()
{ if(status==1)
channel--;
}
void decreaseVolume()
{ if(status==1)
volume--; }
void showVolume()
{ if(status==1)
System.out.println(volume);

void showChannel()
{ if(status==1)
System.out.println(channel);

}
}
class User
{
public static void main(String arg[])
{
Television tele1=new Television();
Television tele2=new Television();
tele1.power();
tele1.increaseChannel();
tele1.showChannel();
tele2.power();
tele2.increaseChannel();
tele2.showChannel();

}
}
A factory manufactures 14 inches television sets. A television
produced by this factory has the following buttons on it.
Power button
Channel Increase Button
Channel Decrease Button
Volume Increase Button
Volume Decrease Button
A Show Channel Button to display the current channel number
A Show Volume Button to display the current volume status.
Model above factory with the help of a class Television. Represent
on/off,volume and channel circuits with data members of type int.
Circuits can not be accessed directly by the users(all private).
All buttons should be represnted with the help of public functions.
also add a constructor to initialize all the data members to 0.
Creat two objects of this class type(purchase the television set from
this factory), push the power button of one television , increase its
channel and then push the show channel button to see the current
channel number.
Repeat these steps for second television.
Also try to display the size of a television in main().
class Television
{
int status;
int volume;
int channel;
public int size;

Television( ){status=0; volume=0;channel=0;size=14;


}
Imagine a tollbooth at a bridge. Cars passing by the booth are
expected to pay 50 cent toll. Mostly they do, but sometime a car goes
by without paying. The tollbooth keeps track of the number of the cars
that have gone by, and of the total amount of money collected.
Model this tollbooth with a class called tollBooth. The two data items
are a type unsigned int to hold the total number of cars, and a type
double to hold the total amount of money collected. A constructor
initializes both of these to 0. A member function called payingCar()
increaments the car total and add 0.50 to the cash total . Another
function called noPayCar() increaments the car total but adds nothing
to the cash total. Finally a member function called display() displays
the two totals.
class TollBooth
{
int totalCars;
float totalCash;
TollBooth()
{
totalCars=0; totalCash=0.0f;
}
void payingCar()
{
totalCars++;
totalCash+=0.5;
}
void nonPayingCar()
{
totalCars++;
}
void display()
{
System.out.println(“Total Cars ”+totalCars+”totalCash ”+
totalCash);
}
}

Anda mungkin juga menyukai