十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
第一题:
创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站建设、成都网站制作、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的利川网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!
Car.java
public class Car {
public String num;
public float price;
public Car(String num,float price){
this.num = num;
this.price=price;
System.out.println("车牌号为:"+num+",价格为:"+price);
}
}
测试类:
public class CarTest {
public static void main(String[] args) {
Car car = new Car("京P34E68", 100000.23f);
}
}
输出为:车牌号为:京P34E68,价格为:100000.23
第二题:
Student.java
public class Student {
private String num;
private String name;
private int age;
private String sex;
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String tell() {
return "Student [num=" + num + ", name=" + name + ", age=" + age+ ", sex=" + sex + "]";
}
public static void main(String[] args) {
Student student = new Student();
student.setAge(18);
student.setNum("001");
student.setName("COLD");
student.setSex("男");
System.out.println(student.tell());
}
}
输出:Student [num=001, name=COLD, age=18, sex=男]
希望能帮到你,望采纳
你好,按照你的要求,代码如下:
-------------------------------------------------------------------------------
1.给定一个User类,要求编写一个用户管理类UserManager
-------------------------------------------------------------------------------
import java.util.HashSet;
public class UserManager {
HashSetUser set = new HashSetUser();
public void add(User user) {
set.add(user);
}
public void del(User user) {
set.remove(user);
}
public boolean isExist(User user) {
return set.contains(user);
}
public void print(User user) {
System.out.println(user.toString());
}
}
class User {
String name;
public String toString() {
return "姓名: " + name;
}
}
-------------------------------------------------------------------------------
2.给定一个Goods类,要求编写一个物品管理类GoodsManager
-------------------------------------------------------------------------------
import java.util.ArrayList;
public class GoodsManager {
ArrayListGoods list = new ArrayListGoods();
public void add(Goods user) {
list.add(user);
}
public void del(Goods user) {
list.remove(user);
}
public Goods select(int id) {
for (Goods goods : list) {
if (goods.id == id) {
return goods;
}
}
return null;
}
public void print() {
for (Goods goods : list) {
System.out.println(goods.toString());
}
}
}
class Goods {
int id;
public String toString() {
return "条形码编号: " + id;
}
}
import java.util.Scanner;
public class WeekJudge{
/**
* @param args
*/
public static void main(String[] args) {
System.out.print("请输入一个数,范围1-7:");
while (true) {
Scanner scanner = new Scanner(System.in);
try {
int x = scanner.nextInt();
if (x 1 || x 7) {
System.out.println("输入数据超出范围,请重新输入");
continue;
}
switch (x) {
case 1: {
System.out.println("星期一");
break;
}
case 2: {
System.out.println("星期二");
break;
}
case 3: {
System.out.println("星期三");
break;
}
case 4: {
System.out.println("星期四");
break;
}
case 5: {
System.out.println("星期五");
break;
}
case 6: {
System.out.println("星期六");
break;
}
default: {
System.out.println("星期日");
break;
}
}
break;
} catch (Exception e) {
System.out.println("输入数据不是数字,请重新输入");
}
}
}
}
public class Student {
private String s_No;
private String s_Name;
private String s_Sex;
private int s_Age;
public Student(String s_No, String s_Name, String s_Sex, int s_Age) {
this.s_No = s_No;
this.s_Name = s_Name;
this.s_Sex = s_Sex;
this.s_Age = s_Age;
}
public void showNo() {
System.out.println("学号:" + this.s_No);
}
public void showName() {
System.out.println("姓名:" + this.s_Name);
}
public void showSex() {
System.out.println("姓别:" + this.s_Sex);
}
public void showAge() {
System.out.println("年龄:" + this.s_Age);
}
public void modifyAge(int age) {
this.s_Age = age;
}
}
import java.util.Scanner;
public class X4_3_2 {
public static void main(String[] args) {
Student s1 = new Student("001", "张三", "男", 12);
Student s2 = new Student("002", "李四", "女", 13);
System.out.println("------------第一个学生的信息------------");
s1.showNo();
s1.showName();
s1.showSex();
s1.showAge();
System.out.println("------------第二个学生的信息------------");
s2.showNo();
s2.showName();
s2.showSex();
s2.showAge();
System.out.println("------------修改第一个学生的年龄------------");
System.out.print("请输入要修改的年龄:");
Scanner scanner = new Scanner(System.in);
int input = scanner.nextInt();
s1.modifyAge(input);
System.out.println("------------第一个学生的信息------------");
s1.showNo();
s1.showName();
s1.showSex();
s1.showAge();
scanner.close();
}
}
下图是运行结果。
n= n * 2
n * a/2
n 为多边形 边数 a 为边长 除以2 是因为 圆周长公式 2πR