Ok it's all about to create 4 class
Class a , class b derived from a and c derived from b and test class
Speed is an instance variable in class b and c.
The method are :
Start() -a method of all class to print the message"hee" override the method in class b and c to print ""hoo" and "hmm" correspondingly
Stop() -a method of class a to print a message"cool" override the method in class b and c to print the "stop"and "stop c" correspondingly
Setspeed() -a method of class b and c to set the value of speed with the value passed to the method .make sure that maximum speed allowed for class b is 75 km/h .if the value to be assigned to speed is more than that assign 75 to E and print the message "over". Similarly the maximum speed for class c is 200 km/h the same for class c
Getspeed(). - a method of class b and c return speed


Increasespeed(). -a method of class b and c .increase the speed with the given value make sure that if the increased value of speed more than 75 km/h for class b then set speed to 75 and print message" neew" dobthe same for class c print the new speed

Write a test class in java and let the user to chose the shape by displaying a menu like below:

1.a
2.b
3.c
4.exit

If the user enter 1 create an instance of class a and call all the method of class a. And make it the same with class b and c call the method in the same class when he chose 4 stop then terminate the program


Make the user to enter their choices repeatedly (use loop) until they press 4 to exit

Recommended Answers

All 10 Replies

You need to at least start on the project in order to get any help, everybody's willing to help but nobody is going to do it for you. Get some code going, and if you run unto any problems, post it here with specific questions as to the problems you are having.

im working on it will post it soon i just have the loop problem with menu

public class a
{

public void Start()
{
System.out.println("Vehicle is Starting");
}
public void Stop()
{
System.out.println("Vehicle is Stopping ");
}
}
-----------------------------------------------------------------------

public class b extends a
{
int speed;
public void start()
{
System.out.println("Car is starting ");

}
public void Stop()
{
System.out.println("Car is Stopping ");
}
public void setSpeed(int a)
{

if (a <=75)
speed = a;
else
System.out.println("Over Speed is not allowed");
}
public int getSpeed()
{
return speed;

}
public void increaseSpeed(int b)
{
int increasedspeed,totalSpeed;
increasedspeed=b;
totalSpeed=increasedspeed+speed;
if (totalSpeed>75)
{
System.out.println("Do not increase too much ");
}

}
}
-------------------------------------------------------------------------------------
public class RacingCar
{
int speed;
public void start()
{
System.out.println(" Racing car is Starting ");

}
public void Stop()
{
System.out.println(" Racing Car is Stopping ");
}
public void setSpeed(int a)
{

if (a <=200)
speed = a;
else
System.out.println("Over Speed is not allowed");
}
public int getSpeed()
{
return speed;

}
public void increaseSpeed(int b)
{
int increasedspeed,totalSpeed;
increasedspeed=b;
totalSpeed=increasedspeed+speed;
if (totalSpeed>200)
{
System.out.println("Do not increase too much ");
}

}
}


i still need to make the the test class and i dont know how to do it because it ask for a menu using loop

Write a test class in java and let the user to chose the shape by displaying a menu like below:

1.a
2.b
3.c
4.exit

If the user enter 1 create an instance of class a and call all the method of class a. And make it the same with class b and c call the method in the same class when he chose 4 stop then terminate the program


Make the user to enter their choices repeatedly (use loop) until they press 4 to exit

I'm having a hard time understanding your instructions.

4 Classes

- Class A
- Class B
- Class C
- Class Speed

Class A <- Class B
Class B <- Class C
Speed will be called in Class B and C.

Is this right thus far?

yes sorry

public class a
{

public void Start()
{
System.out.println("Vehicle is Starting");
}
public void Stop()
{
System.out.println("Vehicle is Stopping ");
}
}
-----------------------------------------------------------------------

public class b extends a
{
int speed;
public void start()
{
System.out.println("Car is starting ");

}
public void Stop()
{
System.out.println("Car is Stopping ");
}
public void setSpeed(int a)
{

if (a <=75)
speed = a;
else
System.out.println("Over Speed is not allowed");
}
public int getSpeed()
{
return speed;

}
public void increaseSpeed(int b)
{
int increasedspeed,totalSpeed;
increasedspeed=b;
totalSpeed=increasedspeed+speed;
if (totalSpeed>75)
{
System.out.println("Do not increase too much ");
}

}
}
-------------------------------------------------------------------------------------
public class c extends b
{
int speed;
public void start()
{
System.out.println(" Racing car is Starting ");

}
public void Stop()
{
System.out.println(" Racing Car is Stopping ");
}
public void setSpeed(int a)
{

if (a <=200)
speed = a;
else
System.out.println("Over Speed is not allowed");
}
public int getSpeed()
{
return speed;

}
public void increaseSpeed(int b)
{
int increasedspeed,totalSpeed;
increasedspeed=b;
totalSpeed=increasedspeed+speed;
if (totalSpeed>200)
{
System.out.println("Do not increase too much ");
}

}
}

I'm guessing you can use a do while loop

do{

}while(!= 4)

something to that extent, I would have to look up my text book to really code this out but that's just the first thing that pops in my head. The menu... could it be a editable comboBox? and have it listen to the users choice? I'm just a beginner programmer first semester so I'm just throwing out ideas for you.

i think we should use
do{

}while(!= 4)
will try it now hope it works two
I'm beginner programmer 2

Thank You soooooooooooooooooooooo much the
do{

}while(!= 4)

worked perfectly

No problem, we "noob" programmers got to stick together. Good luck with your future programming.

We should ;) thanks for you 2 ^_^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.