This is the last programming question in the class, which I wrote in class:
Package book;
Public class Book {
public static void Main (string[] args)
{
& nbsp; books[] Books=new books[3];
books[0]=new Books ("Java Programming", 119.00);
books[1]=new Books ("C language Programming", 72.50);
books[2]=new Books ("Python Programming", 35.85);
for (Books e:books) {
E.setid ();
system.out.println ("title:" +e.getname () + ", ISBN:" +e.getid ()
+ ", Book Price:" +e.getprice ());
}
int N=books.getnextid ();
system.out.println (n);
}
}
Package books;
public class Books {
private static int nextid=0;
private String name;
private int id;
private double price;
Public Books (String n,double p)
{
Name=n;
Id=0;
Price=p;
}
Public String GetName () {
return name;
}
public int getId () {
return ID;
}
Public double GetPrice () {
return price;
}
public void SetId () {
nextid++;
Id=nextid;
}
public static int Getnextid () {
return NextID;
}
}
Next I modified, I think this is OK, please help to check the changes
Package book;
Public class Book {
public static void Main (string[] args)
{
& nbsp; books[] Books=new books[3];
books[0]=new Books ("Java Programming", 119.00f,3);
//Real number defaults to Double,float type real number should be added f/f;
books[1]=new Books ("C language Programming", 72.50f,8);
books[2]=new Books ("Python Programming", 35.85f,5);
for (Books e:books) {
E.setid ();
system.out.println ("title:" +e.getname () + ", ISBN:" +e.getid ()
+ ", Book Price:" +e.getprice () + ", booklet:" +e.getcount ());
}
int n=books.getsumcount ();
system.out.println ("Total number of books:" +n);
}
}
Package book;
Public class Books {
private static int nextid=0;
private String name;
private int id;
private float price;
private int count;
private static int sumcount=0;
Public Books (String name,float price,int count)
(String n,double p)
{
/*name=n;
Id=0;
price=p;*/
This.name=name;
This.id=0;
This.price=price;
This.count=count;
}
Public String GetName () {
return name;
}
public int getId () {
return ID;
}
public float GetPrice () {
return price;
}
public int GetCount () {
return count;
}
public void SetId () {
nextid++;
Id=nextid;
Sumcount+=id*count;
}
public static int Getsumcount () {
return sumcount;
}
}
Through this test, I know I think to the first four chapters very understanding of the content or unfamiliar, I should study the course at the same time to review the previous knowledge, can not feel that they have mastered the not to see.
2016701010126 2016-2071-2 "Java Programming" chapter I-Four summary