2016701010126 2016-2071-2 "Java Programming" chapter I-Four summary

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.