Yard farmer Open Rich peasant, hoe must take first

Source: Internet
Author: User

Package try_2;

Import java.io.*;

/*
* * Author Han
* Function: Take the hoe for me
*/
public class Demo5_2 {
public static void Main (string[] args) throws Exception
{
Dog[] Dogs=new dog[4];
Enter information for each dog from the console
InputStreamReader isr=new InputStreamReader (system.in);//Receive bytes entered from the console
This is similar to Scanner in=new Scanner (system.in)
Constructs a character stream cache that contains characters converted into bytes that are stored in the console input.
BufferedReader br=new BufferedReader (ISR);
Here, with the sentence. Add a stream of characters to the buffered stream
In fact, the above two sentences can be divided into three sentences or a sentence
/* as follows
* InputStream is = system.in;
InputStreamReader ISR = new InputStreamReader (IS);
BufferedReader bufr = new BufferedReader (ISR);
or a sentence
BufferedReader br=new BufferedReader (New InputStreamReader (system.in)); This is good.
*/
for (int i=0;i<4;i++)
{
Dogs[i]=new Dog ();
System.out.println ("Please enter dog name:");
Reading from the console
String Name=br.readline ();
Pay the name to the object
Dogs[i].setname (name);
System.out.println ("Please enter the weight of the dog:");
String S_weight=br.readline ();
Float weight=float.parsefloat (s_weight);//string->float
Pay the weight to the object
DOGS[I].SETWW (weight);
}

Calculate total weight
float allww=0;
for (int i=0;i<4;i++)
{
ALLWW+=DOGS[I].GETWW ();
}
Calculate Average weight
float avgww=allww/dogs.length;
SYSTEM.OUT.PRINTLN ("Total weight =" +allww+ "average =" +avgww);
}
}
Define a Dog class
Class Dog
{
private String name;
private float weight;
Public String GetName ()
{return name;}
public void SetName (String name) {
This.name=name;
}
public float GETWW ()
{
return weight;
}
public void Setww (float weight)
{
This.weight=weight;
}
}

Yard farmer Open Rich peasant, hoe must take first

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.