Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Last active December 27, 2015 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shigemk2/7397050 to your computer and use it in GitHub Desktop.
Save shigemk2/7397050 to your computer and use it in GitHub Desktop.
やさしいJava 13 パッケージ1
package pa;
// 車クラス
class Car
{
private int num;
private double gas;
public Car()
{
num = 0;
gas = 0.0;
System.out.println("車を作成しました");
}
public void setCar(int n, double g)
{
num = n;
gas = g;
System.out.println("ナンバーを"+num+"ガソリン量を"+gas+"にしました");
}
public void show()
{
System.out.println("車のナンバーは"+this.num+"です");
System.out.println("ガソリン量は"+this.gas+"です");
}
}
package pa;
// 車クラス
class Car
{
private int num;
private double gas;
public Car()
{
num = 0;
gas = 0.0;
System.out.println("車を作成しました");
}
public void setCar(int n, double g)
{
num = n;
gas = g;
System.out.println("ナンバーを"+num+"ガソリン量を"+gas+"にしました");
}
public void show()
{
System.out.println("車のナンバーは"+this.num+"です");
System.out.println("ガソリン量は"+this.gas+"です");
}
}
class Sample2
{
public static void main(String[] args)
{
Car car1 = new Car();
car1.show();
}
}
package pa;
class Sample3
{
public static void main(String[] args)
{
Car car1 = new Car();
car1.show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment