0% found this document useful (0 votes)
2 views

java

The document contains Java code for a simple CD rental system, including classes for managing CDs and members. It features methods for adding, deleting, and renting CDs, as well as handling member information. The code also includes calendar functionality to display weekdays and manage dates.

Uploaded by

910564275
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

java

The document contains Java code for a simple CD rental system, including classes for managing CDs and members. It features methods for adding, deleting, and renting CDs, as well as handling member information. The code also includes calendar functionality to display weekdays and manage dates.

Uploaded by

910564275
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

class HelloWorld {

public static void main(String[ ] args)


System.out.println("Hello World!");
}

-startup
plugins/org.eclipse.equinox.launcher_1.5.100.v20180827-1352.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.800.v20180827-1352
-product
org.eclipse.epp.package.jee.product
-showsplash
org.eclipse.epp.package.common
--launcher.defaultAction
openFile
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vmargs
-Dosgi.requiredJavaVersion=1.8
[email protected]/eclipse-workspace
-XX:+UseG1GC
-XX:+UseStringDeduplication
--add-modules=ALL-SYSTEM
-Dosgi.requiredJavaVersion=1.8
-Dosgi.dataAreaRequiresExplicitInit=true
-Xms256m
-Xmx1024m
--add-modules=ALL-SYSTEM

-startup
plugins/org.eclipse.equinox.launcher_1.5.100.v20180827-1352.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.800.v20180827-1352
-product
org.eclipse.epp.package.jee.product
-showsplash
org.eclipse.epp.package.common
--launcher.defaultAction
openFile
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vmargs
-Dosgi.requiredJavaVersion=1.8
[email protected]/eclipse-workspace
-XX:+UseG1GC
-XX:+UseStringDeduplication
--add-modules=ALL-SYSTEM
-Dosgi.requiredJavaVersion=1.8
-Dosgi.dataAreaRequiresExplicitInit=true
-Xms256m
-Xmx1024m
--add-modules=ALL-SYSTEM

/** @author 方雨田


*@author 1711427
*/
import java.text.DateFormatSymbols; //DateFormatSymbols 是一个公共类,用于封装可本地化的日期-时间格式化
数据,如月名、星期几的名称和时区数据。
import java.util.*; //通配符*,导入使用 util 包含的众多类,Calendar,Locale....
public class Month
{
public static void main(String[] args)
{
GregorianCalendar d = GregorianCalendar.getInstance(ENGLISH);

int year =now.get(Calendar.YEAR);


int month = now.get(Calendar.MONTH); //月份是从 0 开始计数的,0-11

String weekdays[] = new DateFormatSymbols().getShortWeekdays(); // 简短


for(int i=1; i<8; ++i)
System.out.print(weekdays[i]+" ");
System.out.println(); //So I'd expect an array which can be indexed with
values 1-7... which means it has to have 8 elements (as all arrays in Java are 0-
based).
now.set(Calendar.DAY_OF_MONTH, 1);
int weeknameofFirstday = now.get(Calendar.DAY_OF_WEEK);//获得当月 1 号是星期几
int cnt = 1;
while(weekdays[cnt] != weekdays[weeknameofFirstday])
{
System.out.print(" ");
++cnt;
}
do
{
int day = now.get(Calendar.DAY_OF_MONTH);
System.out.printf("%3s", day); //printf 为 PrintStream 类中使用指定格式字符串和参数将格式
化的字符串写入此输出流的便捷方法。
System.out.print(" "); //%转换值的长度小于 3,则用空格来填充输出
if(weekdays[now.get(Calendar.DAY_OF_WEEK)] == weekdays[7]) //判断是否需要换行打

System.out.println();
now.add(Calendar.DAY_OF_MONTH, 1);
}while(now.get(Calendar.MONTH) == month);
}
}

package com.aaa;

/**
* @author 方雨田 1711427
*
* 2018 年 11 月 12 日
*/
import java.io.*;

public class CD {
static void addMember()
{
BufferedReader buf1 = new BufferedReader(new
InputStreamReader(System.in));
BufferedReader buf2 = new BufferedReader(new
InputStreamReader(System.in));
String name=new String();
String code=new String();
try {
System.out.print("Enter new member's name :");
name = buf1.readLine();
System.out.print("Enter new member's code :");
code = buf2.readLine();
} catch (IOException e) {
e.printStackTrace();
}
Member m=new Member(name,code);
m.output("members.txt", true);
}
static void rentorsell(boolean ros)
{
BufferedReader buf1 = new BufferedReader(new
InputStreamReader(System.in));
BufferedReader buf2 = new BufferedReader(new
InputStreamReader(System.in));
String name=new String();
String code=new String();
try {
System.out.print("Enter new member's name :");
name = buf1.readLine();
System.out.print("Enter new member's code :");
code = buf2.readLine();
} catch (IOException e) {
e.printStackTrace();
}
Member m=new Member(name,code);
m.output("members.txt", true);
}
static void deleteMember()
{
BufferedReader buf1 = new BufferedReader(new
InputStreamReader(System.in));
String name=new String();
try {
System.out.print("Enter the name of the member to delete:");
name = buf1.readLine();
DataInputStream ois=new DataInputStream(new
BufferedInputStream(new FileInputStream("members.txt")));
Member m=new Member("","");
boolean append=true;
while(m.intput(ois))
{
if(name.equals(m.getName()))
{
if(!m.Returned())
{
System.out.println("CD is not
returned!");
ois.close();
return;
}
else
{
continue;
}
}
if(append)
{
m.output("newMembers.txt", false);
append=false;
}
else
m.output("newMembers.txt",true);
}
ois.close();
append=true;
ois=new DataInputStream(new BufferedInputStream(new
FileInputStream("newMembers.txt")));
while(m.intput(ois))
{
if(append)
{
m.output("members.txt", false);
append=false;
}
else
m.output("members.txt", true);
}
}catch(IOException e)
{
System.out.println(e);
}
}
public static void main(String[] args) throws IOException {
CDrental CD[]=new CDrental[3];
CD[0]=new CDrental(1,"17",12.0f,17.0f,1.0f);
CD[1]=new CDrental(2,"Jocelyn Flores",15.0f,23.0f,1.1f);
CD[2]=new CDrental(3,"Honeymoon",17.0f,25.0f,1.3f);
CD[0].output("CDs.txt", true);
CD[1].output("CDs.txt", true);
CD[2].output("CDs.txt", true);
Member er[]=new Member[2];
er[0]=new Member("ZhangYuan","1726121");
er[1]=new Member("LiuHan","1756324");
er[0].output("member.txt",true);
er[1].output("member.txt",true);

System.out.println("Please select one number from 1 to 7");


System.out.println("1:add member");
System.out.println("2:delete member");
System.out.println("3:rent CD;");
System.out.println("4:sell CD;");
System.out.println("5:stock;");
System.out.println("6:statistics;");
System.out.println("7:return CD;");
int order=(int)System.in.read();
if(order<1||order>7)
{
System.out.println("WRONG!");
}
else
{
switch(order)
{
case 1:
}
}
}

class Member {
private String name;
private String code;
private int CDnumber;
private boolean returned;

Member(String n,String c)
{
name=n;
code=c;
returned=true;
CDnumber=0;
}
String getName()
{
return name;
}
String getCode()
{
return code;
}
boolean Returned()
{
return returned;
}
void setName(String s)
{
name=s;
}
void lend(int a)
{
returned=false;
CDnumber=a;
}

boolean intput(DataInputStream in)


{
try{
name=in.readUTF();
code=in.readUTF();
CDnumber=in.readInt();
}catch(IOException e)
{
return false;
}
return true;
}

void output(String text,boolean app)


{
if(code!=null){
try{
DataOutputStream out=new DataOutputStream(new
BufferedOutputStream(new FileOutputStream(text,app)));
out.writeUTF(name);
out.writeUTF(code);
out.writeInt(CDnumber);
out.close();
}catch(IOException e)
{
System.out.println(e);
}
}
}
}

class CDrental
{
private int number;
private String name;
private float price;
private String owner;
private float saleprice;
private float rentalprice;
private int state;
private int count;

//constructor
CDrental(int m,String n,float p,float sale,float rental)
{
number=m;
name=n;
price=p;
saleprice=sale;
rentalprice=rental;
count=0;
state=0;
}
CDrental(int m,String n,float p,float sale,float rental,String o)
{
number=m;
name=n;
price=p;
saleprice=sale;
rentalprice=rental;
owner=o;
count=0;
state=0;
}

//get()
int getNumber()
{
return number;
}
String getName()
{
return name;
}
float getPrice()
{
return price;
}
float getSaleprice()
{
return saleprice;
}
String getOwner()
{
return owner;
}
float getRentalprice()
{
return rentalprice;
}
int getState()
{
return state;
}

//set
void rent(String n)
{
state=1;
count++;
owner=n;
}
void sale(String n)
{
state=-1;
owner=n;
}
void returned()
{
state=0;
}

boolean input(DataInputStream in)


{
try {
number=in.readInt();
name=in.readUTF();
price=in.readFloat();
saleprice=in.readFloat();
rentalprice=in.readFloat();
state=in.readInt();
count=in.readInt();
}catch(IOException e)
{
return false;
}
return true;
}

void output(String text,boolean app) //false 时覆盖原文件


{
try{
DataOutputStream out=new DataOutputStream(new
BufferedOutputStream(new FileOutputStream(text,app)));
out.writeInt(number);
out.writeUTF(name);
out.writeFloat(price);
out.writeUTF(owner);
out.writeFloat(saleprice);
out.writeFloat(rentalprice);
out.writeInt(state);
out.writeInt(count);
out.close();
}catch(IOException e)
{
System.out.println(e);
}
}
}

You might also like