第一題:
創(chuàng)新互聯(lián)堅持“要么做到,要么別承諾”的工作理念,服務領域包括:成都網站建設、成都網站制作、企業(yè)官網、英文網站、手機端網站、網站推廣等服務,滿足客戶于互聯(lián)網時代的利川網站設計、移動媒體設計的需求,幫助企業(yè)找到有效的互聯(lián)網解決方案。努力成為您成熟可靠的網絡建設合作伙伴!
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("請輸入一個數(shù),范圍1-7:");
while (true) {
Scanner scanner = new Scanner(System.in);
try {
int x = scanner.nextInt();
if (x 1 || x 7) {
System.out.println("輸入數(shù)據超出范圍,請重新輸入");
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("輸入數(shù)據不是數(shù)字,請重新輸入");
}
}
}
}
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 為多邊形 邊數(shù) a 為邊長 除以2 是因為 圓周長公式 2πR