
Patrick B. answered 11/21/20
Math and computer tutor/teacher
/****************************
ALL of this code is not going to fit here...
Please send me an email so I can pass you the source code files
****************************************************/
abstract class Instrument
{
public abstract void Play();
}
class Piano extends Instrument
{
@Override public void Play()
{
System.out.println("Piano is playing tan tan tan tan");
}
}
class Flute extends Instrument
{
@Override public void Play()
{
System.out.println("Flute is playing toot toot toot toot ");
}
}
class Guitar extends Instrument
{
@Override public void Play()
{
System.out.println("Guitar is playing tin tin tin");
}
}
class InstrumentMain
{
public static void main(String args[])
{
Instrument A[] = new Instrument[12];
for (int iLoop=0; iLoop<12; iLoop++)
{
switch (iLoop%3)
{
case 0: { A[iLoop] = new Piano(); break; }
case 1: { A[iLoop] = new Flute(); break; }
case 2: { A[iLoop] = new Guitar(); break; }
}
}
for (int iLoop=0; iLoop<12; iLoop++)
{
System.out.println("------------------------------------");
System.out.println(" object # " + (iLoop+1));
A[iLoop].Play();
if (A[iLoop] instanceof Piano) { System.out.println("Piano"); }
if (A[iLoop] instanceof Flute) { System.out.println("Flute"); }
if (A[iLoop] instanceof Guitar) { System.out.println("Guitar"); }
}
}
}
//*************************************************************************
import java.math.*;
abstract class Compartment
{
public abstract void Notice();
}
class FirstClass extends Compartment
{
@Override public void Notice() { System.out.println("First Class"); }
}
class Ladies extends Compartment
{
@Override public void Notice() { System.out.println("Ladies"); }
}
class General extends Compartment
{
@Override public void Notice() { System.out.println("General"); }
}
class Luggage extends Compartment
{
@Override public void Notice() { System.out.println("Luggage"); }
}
class TestCompartment
{
public static void main(String args[])
{
Compartment A []= new Compartment[10];
int randIntNum=0;
for (int iLoop=0; iLoop<10; iLoop++)
{
randIntNum=0;
while ((randIntNum<1) || (randIntNum>4))
{
randIntNum = (int) (Math.random() *4 + 1);
}
switch (randIntNum)
{
case 1: { A[iLoop] = new FirstClass(); break; }
case 2: { A[iLoop] = new Ladies(); break; }
case 3: { A[iLoop] = new General(); break; }
case 4: { A[iLoop] = new Luggage(); break; }
} //switch
System.out.print(" object # " + (iLoop+1) +" "); A[iLoop].Notice();
}//for
} //main
} //class TestCompartment
//*************************************************************************//
import java.io.*;
class Student
{
protected long rollNum;
protected String name;
Student (long rollNo, String name)
{
this.rollNum = rollNo;
this.name = name;
}
public long GetRollNum() { return(rollNum); }
public String GetName() { return(name); }
}
class Exam extends Student
{
protected double grades[];
public Exam(double scores[], long rollNo, String name)
{
super(rollNo,name);
grades = new double[6];
for (int iLoop=0; iLoop<6; iLoop++)
{
grades[iLoop]=scores[iLoop];
}
}
public double IndexerGetIndexAt(int iIndexPos)
{
double dblReturn=-1;
if ((iIndexPos>=0) && (iIndexPos<6))
{
dblReturn = grades[iIndexPos];
}
return(dblReturn);
}
}
class Result extends Exam
{
protected double total;
protected double avg;
public Result(double grades[],long rollNo, String name)
{
super(grades,rollNo,name);
total=avg=0;
for (int iLoop=0; iLoop<6; iLoop++)
{
this.total += grades[iLoop];
}
this.avg = this.total/6;
}
public double GetTotal() { return(total); }
public double GetAverage() { return(avg); }
}
class ExamResult
{
public void Go()
{
Console console = System.console();
String studentName;
long rollNum;
double grades[] = new double[6];
System.out.print("Please input the student name :>");
studentName = console.readLine();
System.out.print(" Please input the roll # :>");
String inbuff = console.readLine();
rollNum = Long.parseLong(inbuff);
for (int iLoop=0; iLoop<6; iLoop++)
{
System.out.print(" Please input grade # " + (iLoop+1) + " :>");
inbuff = console.readLine();
grades[iLoop] = Double.parseDouble(inbuff);
}
Result result = new Result(grades,rollNum,studentName);
System.out.println(" student name >" + result.GetName() );
System.out.println(" roll # : " + result.GetRollNum());
for (int iLoop=0; iLoop<6; iLoop++)
{
System.out.println(result.IndexerGetIndexAt(iLoop));
}
System.out.println("total is " + result.GetTotal());
System.out.println(" average is " + result.GetAverage());
}
public static void main(String args[])
{
ExamResult x = new ExamResult();
x.Go();
}
}
/************************************************************************/
class Car
{
protected int speed;
protected int noOfGear;
public Car( int speed, int numGears) { this.speed = speed; noOfGear = numGears; }
public void Drive() { speed = 5; noOfGear=3; }
public void SetSpeed(int n) { speed=n; }
public int GetSpeed() { return(speed); }
public int GetNumGears() { return(noOfGear); }
public void Display() { System.out.println(" speed = " + this.speed + " : # of gears = " + noOfGear); }
}
class SportsCar extends Car
{
protected int AirBaloonType;
public SportsCar( int abt, int speed, int numGears)
{
super(speed,numGears);
AirBaloonType = abt;
}
@Override public void Display()
{
System.out.println(" speed = " + this.speed + " : # of gears = " + noOfGear + " : air baloon type = " + AirBaloonType);
}
}
class CarMain
{
public static void main(String args[])
{
SportsCar sportsCar = new SportsCar(1,90,3);
sportsCar.Display();
}
}

Patrick B.
ALL of this code is not going to fit here.... Please send email so I can pass you the source code files11/21/20