当前位置:编程学习 > C#/ASP.NET >>

求帮java转c#的问题

--------------------编程问答--------------------
public class CreditCard {

private String creditNumber;

private String creditType;

private String expiry;

/*constructor function for this class
 */
public CreditCard(String creditNumber, String  creditType,
  String expiry){

this.expiry = expiry;

}


/**
 * @return Returns the creditNumber.
 */
public String getCreditNumber() {
return creditNumber;
}

/**
 * @param creditNumber
 *            The creditNumber to set.
 */
public void setCreditNumber(String creditNumber) {
this.creditNumber = creditNumber;
}

/**
 * @return Returns the creditType.
 */
public String getCreditType() {
return creditType;
}

/**
 * @param creditType
 *            The creditType to set.
 */
public void setCreditType(String creditType) {
this.creditType = creditType;
}

/**
 * @return Returns the expiry.
 */
public String getExpiry() {
return expiry;
}

/**
 * @param expiry
 *            The expiry to set.
 */
public void setExpiry(String expiry) {
this.expiry = expiry;
}




}

===============================================================================

import java.util.Enumeration;
import java.util.Vector;

public class Customer {

private String lastName;

private String firstName;

private CreditCard aCreditCard;

private Member aMember;



/**
 * @param memberType
 * @param lastName
 * @param firstName
 * @param creditNumber
 * @param creditType
 * @param expiry
 */
public Customer(Member aMember, String lastName, String firstName,
CreditCard aCreditCard) {
super();
this.aCreditCard = aCreditCard;
this.lastName = lastName;
this.firstName = firstName;
this.aMember = aMember;
}




/**
 * @return Returns the firstName.
 */
public String getFirstName() {
return firstName;
}

/**
 * @param firstName
 *            The firstName to set.
 */
public void setFirstName(String firstName) {
this.firstName = firstName;
}

/**
 * @return Returns the lastName.
 */
public String getLastName() {
return lastName;
}

/**
 * @param lastName
 *            The lastName to set.
 */
public void setLastName(String lastName) {
this.lastName = lastName;
}

/**
 * @return Returns the credit card.
 */
public CreditCard getCustomerCreditCard() {
return aCreditCard;
}

/**
 * @param lastName
 *            The lastName to set.
 */
public void setCustomerCreditCard(CreditCard aCreditCard) {
this.aCreditCard = aCreditCard;

}


/**
 * @return Returns the lastName.
 */
public Member getCustomerMember() {
return aMember;
}

/**
 * @param lastName
 *            The lastName to set.
 */
public void setCustomerMember(Member aMember) {
this.aMember = aMember;

}




}

====================================================================================

public class CustomerBooking {
private int priceCode;
private int numberOfSeats;
private Customer theCust;
private int rowNum;
private int startSeatNum;

public String toString() {
return "Price code =" + priceCode + ", seats booked = " + numberOfSeats + ", sitting at row " + rowNum;
}
/**
 * @param priceCode
 * @param theCust
 * @param rowNum
 * @param startSeatNum
 */
public CustomerBooking(int priceCode, Customer theCust, int rowNum,
int startSeatNum, int seatsBooked) {
super();
this.priceCode = priceCode;
this.theCust = theCust;
this.rowNum = rowNum;
this.startSeatNum = startSeatNum;
this.numberOfSeats = seatsBooked;
}
/**
 * @return Returns the numberOfSeats.
 */
public int getNumberOfSeats() {
return numberOfSeats;
}
/**
 * @param numberOfSeats The numberOfSeats to set.
 */
public void setNumberOfSeats(int numberOfSeats) {
this.numberOfSeats = numberOfSeats;
}
/**
 * @return Returns the priceCode.
 */
public int getPriceCode() {
return priceCode;
}
/**
 * @param priceCode The priceCode to set.
 */
public void setPriceCode(int priceCode) {
this.priceCode = priceCode;
}
/**
 * @return Returns the rowNum.
 */
public int getRowNum() {
return rowNum;
}
/**
 * @param rowNum The rowNum to set.
 */
public void setRowNum(int rowNum) {
this.rowNum = rowNum;
}
/**
 * @return Returns the startSeatNum.
 */
public int getStartSeatNum() {
return startSeatNum;
}
/**
 * @param startSeatNum The startSeatNum to set.
 */
public void setStartSeatNum(int startSeatNum) {
this.startSeatNum = startSeatNum;
}
/**
 * @return Returns the theCust.
 */
public Customer getTheCust() {
return theCust;
}
/**
 * @param theCust The theCust to set.
 */
public void setTheCust(Customer theCust) {
this.theCust = theCust;
}
}

========================================================================================

public class Reservation {
private int priceCode;
private int numberOfSeats;
private Customer theCust;
private int rowNum;
private int startSeatNum;

public String toString() {
return "Price code =" + priceCode + ", seats booked = " + numberOfSeats + ", sitting at row " + rowNum;
}
/**
 * @param priceCode
 * @param theCust
 * @param rowNum
 * @param startSeatNum
 */
public Reservation(int priceCode, Customer theCust, int rowNum,
int startSeatNum, int seatsBooked) {
super();
this.priceCode = priceCode;
this.theCust = theCust;
this.rowNum = rowNum;
this.startSeatNum = startSeatNum;
this.numberOfSeats = seatsBooked;
}
/**
 * @return Returns the numberOfSeats.
 */
public int getNumberOfSeats() {
return numberOfSeats;
}
/**
 * @param numberOfSeats The numberOfSeats to set.
 */
public void setNumberOfSeats(int numberOfSeats) {
this.numberOfSeats = numberOfSeats;
}
/**
 * @return Returns the priceCode.
 */
public int getPriceCode() {
return priceCode;
}
/**
 * @param priceCode The priceCode to set.
 */
public void setPriceCode(int priceCode) {
this.priceCode = priceCode;
}
/**
 * @return Returns the rowNum.
 */
public int getRowNum() {
return rowNum;
}
/**
 * @param rowNum The rowNum to set.
 */
public void setRowNum(int rowNum) {
this.rowNum = rowNum;
}
/**
 * @return Returns the startSeatNum.
 */
public int getStartSeatNum() {
return startSeatNum;
}
/**
 * @param startSeatNum The startSeatNum to set.
 */
public void setStartSeatNum(int startSeatNum) {
this.startSeatNum = startSeatNum;
}
/**
 * @return Returns the theCust.
 */
public Customer getTheCust() {
return theCust;
}
/**
 * @param theCust The theCust to set.
 */
public void setTheCust(Customer theCust) {
this.theCust = theCust;
}
}


=========================================================================
public class Member {
public static final int NONMEMBER = 0;

public static final int BRONZE = 1;

public static final int SILVER = 2;

public static final int GOLD = 3;

private int memberType;

/**prameterised constructor of member
 * class
 */
public Member(int memberType){

this.memberType = memberType;
}


/**
 * @return Returns the memberType.
 */
public int getMemberType() {
return memberType;
}

/**
 * @param memberType
 *            The memberType to set.
 */
public void setMemberType(int memberType) {
this.memberType = memberType;
}

}
=================================================================================
public class Row {
public static final int STALLS=0;
public static final int DRESSCIRCLE=1;
public static final int BALCONY=2;

private int priceCode;
private int numberAvailable;
private int currentSeat;
private int lastBooked;

public Row(int numAvail, int code) {
this.priceCode = code;
this.numberAvailable = numAvail;
currentSeat = 1;
lastBooked = 1;
}

public boolean bookSeats(int num) {
if (numberAvailable >= num) {
lastBooked = currentSeat;
currentSeat += num;
numberAvailable -= num;
return true;
}
return false;
}

public int getPriceCode() {
return priceCode;
}

public int getCurrentSeat() {
return currentSeat;
}

public int getLastBooked() {
return lastBooked;
}

}
================================================================

地方不够了。。。。
--------------------编程问答--------------------
test部分
public class RowTest extends TestCase {

/**
 * Constructor for RowTest.
 * @param arg0
 */
public RowTest(String arg0) {
super(arg0);
}

public void testBookSeats() {
Row aRow = new Row(1, 1);
assertEquals(aRow.bookSeats(1), true);
}

}
==========================================================


import java.util.Vector;

public class TestRun {

// the theatre will have 5 rows in the stalls each with 6 seats
private static final int STALLNO = 5;
private static final int STALLSEATS = 6;
// the theatre will have 4 rows in the DC each with 6 seats
private static final int DCNO = 4;
private static final int DCSEATS = 6;
// the theatre will have 2 rows in the balcony each with 6 seats
private static final int BALCONYNO = 2;
private static final int BALCONYSEATS = 6;

public static void main(String[] args) {
// create a new theatre
Theatre theTheatre = new Theatre();
populate(theTheatre);

// create some customers
Member normalMember = new Member(Member.NONMEMBER);
CreditCard normalCreditCard = new CreditCard("2345678", "VISA", "12/04");
Customer normal = new Customer(normalMember, "Smith", "Joel",normalCreditCard);


Member bronzeMember = new Member(Member.BRONZE);
CreditCard bronzeCreditCard = new CreditCard("6876543", "MasterCard", "03/06");
Customer bronze = new Customer(bronzeMember, "Jones", "Bruce", bronzeCreditCard);



Member silverMember = new Member(Member.SILVER);
CreditCard silverCreditCard = new CreditCard( "9976543", "VISA", "02/06");
Customer silver = new Customer(silverMember, "Dell", "George",silverCreditCard);


Member goldMember = new Member(Member.GOLD);
CreditCard goldCreditCard = new CreditCard("9876543", "MasterCard", "03/08");
Customer gold = new Customer(goldMember, "Dell", "Bruce", goldCreditCard);

// make some bookings print the charges
Booking bookings = new Booking(theTheatre);

// book five seats in the stalls for a nonmember
bookings.bookSeats(Row.STALLS, 5, normal);
System.out.println("Five seats in the stalls for nonmember = $" + bookings.getCharge(normal));
System.out.println("You are seated in row "+bookings.getCustomerBooking(normal).getRowNum()
+", seat "+bookings.getCustomerBooking(normal).getStartSeatNum()
+" to seat "+(bookings.getCustomerBooking(normal).getStartSeatNum()+bookings.getCustomerBooking(normal).getNumberOfSeats()-1));

// book five seats in the stalls for a bronze member
bookings.bookSeats(Row.STALLS, 5, bronze);
System.out.println("Five seats in the stalls for bronze member = $" + bookings.getCharge(bronze));
System.out.println("You are seated in row "+bookings.getCustomerBooking(bronze).getRowNum()
+", seat "+bookings.getCustomerBooking(bronze).getStartSeatNum()
+" to seat "+(bookings.getCustomerBooking(bronze).getStartSeatNum()+bookings.getCustomerBooking(bronze).getNumberOfSeats()-1));

// book one seat in the stalls for a silver member
bookings.bookSeats(Row.STALLS, 1, silver);
System.out.println("One seat in the stalls for silver member = $" + bookings.getCharge(silver));
System.out.println("You are seated in row "+bookings.getCustomerBooking(silver).getRowNum()
+", seat "+bookings.getCustomerBooking(silver).getStartSeatNum()
+" to seat "+(bookings.getCustomerBooking(silver).getStartSeatNum()+bookings.getCustomerBooking(silver).getNumberOfSeats()-1));

// two seats in the balcony for a gold member
bookings.bookSeats(Row.BALCONY, 2, gold);
System.out.println("Two seats in the balcony for gold member = $" + bookings.getCharge(gold));
System.out.println("You are seated in row "+bookings.getCustomerBooking(gold).getRowNum()
+", seat "+bookings.getCustomerBooking(gold).getStartSeatNum()
+" to seat "+(bookings.getCustomerBooking(gold).getStartSeatNum()+bookings.getCustomerBooking(gold).getNumberOfSeats()-1));

}

private static void populate(Theatre theTheatre) {
// initialise the stalls
Vector theStalls = theTheatre.getStalls();
theStalls = addingVector(STALLNO, theStalls, 0);

// initialise the dc
Vector theDc = theTheatre.getDressCircle();
theDc= addingVector(DCNO, theDc, 1);

// initialise the Balcony
Vector theBalcony = theTheatre.getBalcony();

theBalcony = addingVector(BALCONYNO, theBalcony, 2);
}

public static Vector addingVector(int seatNo, Vector theatreSection, int seatFlag){

for (int x=0; x < seatNo; x++) 
{
Row theRow;
if(seatFlag == 0){
theRow = new Row(STALLSEATS, Row.STALLS);
theatreSection.add(theRow);
}

if(seatFlag == 1){
theRow = new Row(DCSEATS, Row.DRESSCIRCLE);
theatreSection.add(theRow);
}

if(seatFlag == 2){
theRow = new Row(BALCONYSEATS, Row.BALCONY);
theatreSection.add(theRow);
}
}

return theatreSection;
}

}
public class TestRunTest extends TestCase {

/**
 * Constructor for TestRunTest.
 * @param arg0
 */
public TestRunTest(String arg0) {
super(arg0);
}

public static void TestAddingVector(){

//TestRun mainTest = new TestRun();

Vector theatreSection = new Vector();
theatreSection.add("BALCONYSEATS");
theatreSection.set( 0, (TestRun.addingVector(2,  theatreSection,2 ) ));
assertEquals(theatreSection.get(0), "BALCONYSEATS");
//String args[] = new String();//"");
//TestRun.main("");

}
}
import java.util.Enumeration;
import java.util.Vector;

public class Theatre {

private static final double STALLCHARGE = 35.25;
private static final double DRESSCIRCLECHARGE = 45.80;
private static final double BALCONYCHARGE = 85.00;
private static final double BRONZEDISCOUNT = 0.90;
private static final double SILVERDISCOUNT = 0.75;
private static final double GOLDDISCOUNT = 0.5;

private Vector stalls = new Vector();
private Vector dressCircle = new Vector();
private Vector balcony = new Vector();

public static double getDiscount(int memberCode) {
if (memberCode == Member.BRONZE)
return  BRONZEDISCOUNT;
if (memberCode == Member.SILVER)
return  SILVERDISCOUNT;
if (memberCode == Member.GOLD)
return  GOLDDISCOUNT;
return 1;
}

public double getCharge(int priceCode) {
if (priceCode == Row.STALLS)
return STALLCHARGE;
if (priceCode == Row.DRESSCIRCLE)
return DRESSCIRCLECHARGE;
if (priceCode == Row.BALCONY)
return BALCONYCHARGE;
return -1;
}

/**
 * @return Returns the balcony.
 */
public Vector getBalcony() {
return balcony;
}

/**
 * @param balcony
 *            The balcony to set.
 */
public void setBalcony(Vector balcony) {
this.balcony = balcony;
}

/**
 * @return Returns the dressCircle.
 */
public Vector getDressCircle() {
return dressCircle;
}

/**
 * @param dressCircle
 *            The dressCircle to set.
 */
public void setDressCircle(Vector dressCircle) {
this.dressCircle = dressCircle;
}

/**
 * @return Returns the stalls.
 */
public Vector getStalls() {
return stalls;
}

/**
 * @param stalls
 *            The stalls to set.
 */
public void setStalls(Vector stalls) {
this.stalls = stalls;
}



}
====================================

import junit.framework.TestCase;
import java.math.BigDecimal;
import java.util.Vector;
import java.util.HashMap;

public class TheatreBookingTest extends TestCase {

/**
 * Constructor for TheatreBookingTest.
 * @param arg0
 */
public TheatreBookingTest(String arg0) {
super(arg0);
}

public static void testGetCharge() {
Member goldMember = new Member(Member.GOLD);
CreditCard goldCreditCard = new CreditCard("1111", "MasterCard", "03/08");
Customer gold = new Customer(goldMember, "Abul", "Khayer", goldCreditCard);


Vector theatreArea = new Vector();
theatreArea.add("DRESSCIRCLECHARGE");
Theatre theTheatre = new Theatre();
theTheatre.setDressCircle( theatreArea); 
//theTheatre.setCharge();
Row theRow = new Row(6, 2);
int priceCode = Row.DRESSCIRCLE;
int number = 3;
int rowNum = 4;
CustomerBooking  theBooking= new CustomerBooking ( priceCode, gold, rowNum,
2, 3); 

TheatreBooking  testTheatre = new TheatreBooking(theTheatre);
assertEquals(testTheatre.bookingConfirmation( theatreArea, theRow, priceCode, number,  gold ), true);

TheatreBooking chargeTest = new TheatreBooking(theTheatre);
BigDecimal result = chargeTest.getCharge(gold);
//BigDecimal testValue = 89.98;

//assertTrue(result, 2.89);

}

}
=========================
public class TheatreTest extends TestCase {

/**
 * Constructor for TheatreTest.
 * @param arg0
 */
public TheatreTest(String arg0) {
super(arg0);
}

public static void testGetDiscount() {
Theatre temp=new Theatre();
System.out.println(temp.getDiscount(0));
assertTrue(temp.getDiscount(0)== Member.BRONZE);

}

}
--------------------编程问答-------------------- 请问你这份作业完成了没
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,