1.进制转换

/*
企业发放的奖金根据利润提成。
利润(I)低于或等于10万元时,奖金可提10%;
利润高于10万元,低于20万元时,
低于10万元的部分按10%提成,高于10万元的部分,可提成7.5%;
20万到40万之间时,高于20万元的部分,可提成5%;
40万到60万之间时高于40万元的部分,可提成3%;
60万到100万之间时,高于60万元的部分,可提成1.5%,
高于100万元时,超过100万元的部分按1%提成,
从键盘输入当月利润I,求应发放奖金总数?
*/
import java.util.Scanner;
public class Demo1 { public static void main(String args[]) {
/*
System.out.println("二进制:4 " +Integer.toBinaryString(4));
System.out.println("八进制:16 " +Integer.toOctalString(16));
System.out.println("十六进制:10 " + Integer.toHexString(10));
int a = 12328;
int b,c,d,e,f;
//取个位
b = a % 10;
//c = a % 100 / 10;
c = a / 10 % 10;
d = a / 100 % 10;
e = a / 1000 % 10;
f = a / 10000;
System.out.println("b = " + b + "\tc = " + c);
System.out.println("d = " + d + "\te = " + e + "\tf = " + f); int a = 462,b,c,d,e,f;
if(a < 10){
System.out.println("1位数...");
} else if ( a < 100 ) {
b = a % 10;
c = a / 10 % 10;
System.out.println("2位数..." + b + c);
} else if ( a < 1000 ) {
b = a % 10;
c = a / 10 % 10;
d = a / 100 % 10;
System.out.println("3位数..." + b + c + d);
} else if ( a < 10000 ) {
b = a % 10;
c = a / 10 % 10;
d = a / 100 % 10;
e = a / 1000 % 10;
System.out.println("4位数..." + b + c + d + e);
} else {
b = a % 10;
c = a / 10 % 10;
d = a / 100 % 10;
e = a / 1000 % 10;
f = a / 10000;
System.out.println("5位数..." + b + c + d + e + f);
} Scanner scan = new Scanner(System.in);
System.out.println("请输入你信息姓名、年龄、成绩:");
String name = scan.next();//获取字符串
int age = scan.nextInt();//获取整型数字
double score = scan.nextDouble();
System.out.println("输入的信息如下:");
System.out.println("姓名:" + name + " 年龄:" + age + " 成绩:" + score); Scanner scan = new Scanner(System.in);
System.out.println("请输入利润:");
double I = scan.nextDouble();
double bound = 0;
//奖金方案
if(I <= 10) {
bound = I * 0.1;
} else if( I < 20 ) {
bound = 10 * 0.1 + (I - 10) * 0.075; // 35 10 10 0.075
} else if( I < 40 ) {
bound = 10 * 0.1 + 10 * 0.075 + (I - 20) * 0.05;
} else if( I < 60 ) {
bound = 10 * 0.1 + 10 * 0.075 + 20 * 0.05 + (I - 40) * 0.03;
} else if( I < 100 ) {
bound = 10 * 0.1 + 10 * 0.075 + 20 * 0.05 + 20 * 0.03 + (I - 60) * 0.015;
} else {
bound = 10 * 0.1 + 10 * 0.075 + 20 * 0.05 + 20 * 0.03 + 40 * 0.015 + (I - 100) * 0.01;
}
System.out.println("奖金:" + bound);
//String s = NULL;
*/
int a = 1, b = 6, c = 9;
if(a > b){
if(a > c){
if(b > c){
System.out.println("@:" + a + b + c);
} else {
System.out.println(" :" + a + c + b);
}
} else {
System.out.println(" :" + c + a + b);
}
} else {
if(b > c) {
if( a > c){
System.out.println(" :" + b + a + c);
} else {
System.out.println(" :" + b + c + a);
} } else {
System.out.println("** :" + c + b + a);
} } int year = 2012;
boolean isLeapYear = year % 400 == 0 || year % 4 == 0 && year % 100 != 0; }
}

2.封装类

//声明类  类封装
public class Student { String name;
char sex;
private int age;//属性私有
int sno;
//提供访问属性的方法 通过方法防止非法数据存入属性
void setAge() {
age = 30;
if(age > 150 || age < 0){
System.out.println("年龄不合法...");
age = 0;
} } int getAge() {
return age; //返回age属性值
} void study() {
System.out.println("学习!...");
} //方法
void speak() {
System.out.println("大家好!...");
} }

3.测试类

//声明类
public class StudentTest {
public static void main(String[] args){
Student o = new Student();//创建自定义对象
//o 学生对象 Student 类 int a = 20; System.out.println("o.name = " + o.name);
o.speak();//方法调用
o.study(); o.name = "张三";
o.sex = '男';
//o.age = -20;
o.setAge();
o.sno = 180; o.name = "张飞";
System.out.println("o.name = " + o.name);
System.out.println("o.sex = " + o.sex);
//System.out.println("o.age = " + o.age);
System.out.println("o.getAge() = " + o.getAge());
System.out.println("o.sno = " + o.sno); }
}

4.测试类1

//声明类
public class StudentTest1 {
public static void main(String[] args){
Student s = null;//声明对象的引用
//s.study(); new
s = new Student();//new 创建对象 实例化对象
s.name = "李四";
System.out.println("s.name = " + s.name);
s.study(); Student s2 = new Student();
s2.name = "张三";
System.out.println("s2.name = " + s2.name);
System.out.println("s.name = " + s.name);
s2.study(); }
}

5.类说明

//声明类
public class Obj { //状态 属性 实例变量
String name;
char sex;
int age; //行为 方法 动作
void speak() {
System.out.println("大家好!...");
} }
//////////////////////////////////
class ObjTest {
public static void main(String[] args){
Obj o = new Obj();//创建自定义对象
//Random ran = new Random(); System.out.println("o.name = " + o.name);
o.speak();
o.name = "张三";
o.sex = '男';
o.age = 20; o.name = "张飞";
System.out.println("o.name = " + o.name);
System.out.println("o.sex = " + o.sex);
System.out.println("o.age = " + o.age); }
}

6.类方法

//声明类
public class MethodTest1 { int a = 10;//与对象关联
//方法 无参数 无返回值
void method1() {
System.out.println("call method1()");
}
//返回值类型 add 方法名 ()传入参数
void add (int a, int b) {
int sum = a + b;
System.out.println("sum = " + sum);
}
//形参列表 数据类型 变量名
double caluSal(int job,int house,int bound) {
//System.out.println("sum = " + job + house + bound);
return job + house + bound;// return返回计算结果
} public static void main(String[] args){
MethodTest1 mt = new MethodTest1();
int b = mt.a;
System.out.println("b = " + b);
mt.method1();
mt.add(10, 6);//调用时 参数类型 个数与声明的方法匹配 double salary = mt.caluSal(8000,5000,6000); System.out.println("salary = " + salary);
//结果返回还需要处理
double result = salary * 0.05; System.out.println("result = " + result);
}
}

java新手笔记5 类的更多相关文章

  1. java新手笔记18 类比较

    1.Shap类 package com.yfs.javase; public class Shape /*extends Object */{ //默认继承object object方法全部继承 // ...

  2. java新手笔记9 类的封装示例

    1.bank类 package com.yfs.javase; //类封装 public class BankCard { //属性 int balance;//默认0 实例变量 分配给每个对象一个 ...

  3. java新手笔记11 类的静态属性、方法(单例)

    1.Person类 package com.yfs.javase; public class Person { String name;//每个对象上分配 与对象绑定 int age; char se ...

  4. java新手笔记14 类继承示例

    1.Person package com.yfs.javase; public class Person { private String name; private int age; private ...

  5. Java学习笔记——File类之文件管理和读写操作、下载图片

    Java学习笔记——File类之文件管理和读写操作.下载图片 File类的总结: 1.文件和文件夹的创建 2.文件的读取 3.文件的写入 4.文件的复制(字符流.字节流.处理流) 5.以图片地址下载图 ...

  6. Java学习笔记之---类和对象

    Java学习笔记之---类和对象 (一)类 类是一个模板,它描述一类对象的行为和状态  例如:动物类是一个类,动物们都有属性:颜色,动物们都有行为:吃饭 public class Dog { Stri ...

  7. java新手笔记8 包

    1.main函数 public class MainParam { //考察main 方法的参数 args //运行时可以传入参数 参数类型 String public static void mai ...

  8. java新手笔记3 运算符&循环

    1.包 2.运算符 public class Operator { public static void main(String[] args) { int a = 5; System.out.pri ...

  9. java新手笔记31 集合实现类

    Person类: package com.yfs.javase; import java.util.Date; public class Person implements Comparable { ...

随机推荐

  1. Java笔记(二十一)……String与StringBuffer

    String类 String类是一个特殊的类,叫做只读类,一旦创建了对象,便不可被改变,同样"abc"既为一个常量,也为一个对象,也是不可以改变的 String s1 = &quo ...

  2. HW5.23

    public class Solution { public static void main(String[] args) { int count = 0; for(int i = 0; i < ...

  3. POJ1873 - Balance(01背包)

    题目大意 现有一个天平,它有C个挂钩和G个砝码,问有多少种方法可以使得天平平衡(砝码必须用完) 题解 其实就是让背包容量为0的方法有多少种方法,但是这样的话背包容量会出现负数,所以可以平移一下,背包容 ...

  4. CF_402C Searching for Graph 乱搞题

    题目链接:http://codeforces.com/problemset/problem/402/C /**算法分析: 乱搞题,不明白题目想考什么 */ #include<bits/stdc+ ...

  5. 创建二叉树,C语言实现

    一.前序遍历创建二叉树,使用递归,头文件 BiTree.h /*槽点一:创建树时用scanf输入不成功*/ #ifndef BITREE_H #define BITREE_H #include< ...

  6. OS X: Keyboard shortcuts

    Using keyboard shortcuts To use a keyboard shortcut, press a modifier key at the same time as a char ...

  7. 尝试获取TextBox_TextChanged事件订阅列表过程

    项目中有用到动态事件绑定[多种事件],由于可触发多次绑定,所以想获取订阅列表来判断是否已绑定事件,从而避免问题! 查找相关资料得知Delegate的GetInvocationList方法可以获取委托的 ...

  8. java 泛型中 T、E ... 和 问号(通配符)的区别

    一.泛型中T.E ...  是泛型类.泛型方法定义时候用的. 1.泛型类定义在类后面 紧跟类名后面 public class TestClassDefine<T>{} 2.泛型方法定义在方 ...

  9. 手动建立数据库连接的BaseDAO

    package com.chinasoft.julong.dao; import java.sql.Connection; import java.sql.DriverManager; import ...

  10. TDD中的迭代

    博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:TDD中的迭代.